
Here, we define the __init__ method as taking a parametername (along with the usualself). Here, we just create a new field also calledname. Notice these are two different variables even though they have the same name. The dotted notation allows us to differentiate between them.
Most importantly, notice that we do not explicitly call the __init__ method but pass the arguments in the parentheses following the class name when creating a new instance of the class. This is the special significance of this method.
Now, we are able to use theself.name field in our methods which is demonstrated in thesayHi method.Describe what you're looking for in as much detail as you'd like.
Our AI reads your request and finds the best matching books for you.
Popular searches:
Join 2 million readers and get unlimited free ebooks