So first of all it should be
def __init__(mysillyobjecct, name, age).
Normally when we declare classes, the first variable that a function takes (like
myfunc in this example) is a variable, or pointer, to itself. Convention is that this variable is called
self. In this example you use two different names for
self. In the constructure you use
mysillyobject and in
myfunc you use
abc. Because both these functions are part of the same class, they refer to the same object, ie
self. you can use different names in the different functinos but they all refer to
self. The first variable in any class method will be
self, no matter what you call it.
In other words,
mysillyobject.name , which is declared in the constructor and therefore available in the entire class, is exactly the same as
abc.name. The code should really be written as follows:
def __init__(self, name, age):
self.name = name
self.age = age
print("Hello my name is " + self.name)
p1 = Person("John", 36)
Here you can see why it works. You just used different names for
self in the different methods, but in this case it does not create different variables. They all refer to what we normally use as
Hope this helps!