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



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


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

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.


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


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(['a', 'b', 'c'])

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


2 posts were split to a new topic: The len() built-in function


Is that strictly true since str() would do something with the variable by turning it into a string, rather than just tell us something about it like len() may do?


str() doesn’t actually change the variable, but tells us what the string version would be, so it’s still telling us something about the variable.