Python - Constructors and Object Initialization
What will be the output of this code?
class Cat:
def __init__(self, name):
self.name = name
c = Cat('Whiskers')
print(c.name)What will be the output of this code?
class Cat:
def __init__(self, name):
self.name = name
c = Cat('Whiskers')
print(c.name)__init__ sets attribute__init__ method assigns the string 'Whiskers' to self.name.c.name outputs 'Whiskers'.__init__ prints value [OK]15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions