0
How is following class initialization working
class Mry: print " Hello Mry" After execution of above lines, it is printing o/p as Hello Mry My doubt here how is it printing w/o creating any object of class or calling class itself as in case of class attributes.
1 Odpowiedź
+ 2
It is printing because you have put ot directly inside the body of the class without defining an initiator. Try this:
class Mry:
def __init__(self):
print("Hello Mry")
This will print "Hello Mry" only when you construct it by:
Mry()
<code is for python 3>