Python - Constructors and Object Initialization
Find the error in this class definition:
class Person:
def __init__(name):
self.name = name
p = Person("Alice")Find the error in this class definition:
class Person:
def __init__(name):
self.name = name
p = Person("Alice")__init__ method parameters__init__ method must have self as the first parameter, but it is missing here.selfself, self.name causes an error because self is undefined.self parameter in __init__ -> Option B__init__ needs self first [OK]self as first __init__ parameter [OK]self in method parameters15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions