- #1
- 1,427
- 96
- TL;DR Summary
- Understanding dot notation in general
Hello (again).
I have become quite familiar with the dot notation in Python. The dot "operator", assuming operator is the right term, seem to have many uses.
For example:
1) After an instance name, it can be used to access instance attributes and apply instance methods to the object/instance itself.
2) After importing a module, it can be used be used to access functions inside the module, access classes contained inside the module to create objects, access variables contained inside the module, what else?
Example:
Is that correct? I feel like it should be called the "access" operator since it allows us to access things.
What are the exact inner working and the more general definition the dot notation/dot operator?
Everything in Python is an object, as we repeatedly mentioned. So also a module, which can contain functions, classes, variables, objects, lines of code, should be considered an object in some sense...What class would a module belong to?
Thanks!
I have become quite familiar with the dot notation in Python. The dot "operator", assuming operator is the right term, seem to have many uses.
For example:
1) After an instance name, it can be used to access instance attributes and apply instance methods to the object/instance itself.
Code:
car1=Car()
car1.speed #speed is the attributed
car1.turn #turn is the method
2) After importing a module, it can be used be used to access functions inside the module, access classes contained inside the module to create objects, access variables contained inside the module, what else?
Example:
Code:
import module1 #import a user-defined module called module1
module1.function1 #access a particular function called function1 inside the module
object1=module1.Class1() #create an object called object 2 from Class 1 contained inside the module
module1.object2.attribute1 #access a specific attribute of object2 contained inside the module
module1.object2.method1 #access a specific method of object2 contained inside the module
Is that correct? I feel like it should be called the "access" operator since it allows us to access things.
What are the exact inner working and the more general definition the dot notation/dot operator?
Everything in Python is an object, as we repeatedly mentioned. So also a module, which can contain functions, classes, variables, objects, lines of code, should be considered an object in some sense...What class would a module belong to?
Thanks!