Why do some methods use dot notation when others don’t?


#1

Question

Why do some methods use dot notation when others don’t?

Answer

Python is an object-oriented language, meaning it’s built around the idea of objects making things more scalable and reusable. You’ll be introduced to objects in depth later in the course, but for now think of objects as being built from blueprints that specify that object’s properties and methods.
Dot notation allows us to use methods belonging to an object. For example, if we had a Car object it might have an ignition( ) method that we can use to turn the car on. Strings are objects just like a Car could be, and they have methods you can make use of, like upper( ) and lower( ).
Other methods that don’t use dot notation are not dependent on being attached to an object, and might even be built into the language, like the len( ) method you learned about!


FAQ: Learn Python – Strings & Console Output – Dot Notation
#2

An easier way to think about it would be that the methods using dot notation do something to the variable while the others tell us something about it.


#3

In the course it is mentioned that
Methods that use dot notation only work with strings.

On the other hand, len() and str() can work on other data types.

So can you give some example on the the behalf of above mentioned statements


#4

that is not entirely true, there are also methods for other data types:

print ['a', 'b', 'c'].pop(1) # will output: b

so methods are data type specific while built-in function will work on multiple data types:

len("string")
len(['a', 'b', 'c'])

you will grasp this better once you learned about functions, classes and methods