+ 1

In Python, how does one specify the difference between a module and an object just before the period?

In Python, there's a way to use the '.' symbol just after modules and objects and before methods.

28th Dec 2022, 3:46 AM
guiltFear7
5 Answers
+ 4
If I understand your question correctly I belive this is the answer? "All methods must have self as their first parameter, although it isn't explicitly passed, Python adds the self argument to the list for you; you do not need to include it when you call the methods. Within a method definition, self refers to the instance calling the method. Instances of a class have attributes, which are pieces of data associated with them. In this example, Cat instances have attributes color and legs. These can be accessed by putting a dot, and the attribute name after an instance. In an __init__ method, self.attribute can therefore be used to set the initial value of an instance's attributes." class Cat: def __init__(self, color, legs): self.color = color self.legs = legs felix = Cat("ginger", 4) print(felix.color)
28th Dec 2022, 6:50 AM
Eugene
Eugene - avatar
+ 1
Interesting, but not quite. I meant to refer to cases in which a function is after the period, such as txt.sort(). In such cases, it's unclear if the part before the period is an argument as though sort(txt) or a class such as List.sort().
28th Dec 2022, 9:10 PM
guiltFear7
28th Dec 2022, 10:26 PM
Bob_Li
Bob_Li - avatar
+ 1
I haven't gotten there in the lessons, so I don't know what the difference is between the types of methods.
29th Dec 2022, 1:03 AM
guiltFear7
+ 1
Take your time to understand the basic concepts. They all stack upon each other and you should build a solid foundation first. Curiosity is a good sign, because that means you are learning actively.đŸ€“
29th Dec 2022, 1:17 AM
Bob_Li
Bob_Li - avatar