External Exam Download Resources Web Applications Games Recycle Bin

Constructor and Instance Variable

constructor and instance variable.py

class Human:
  def __init__(self): #constructor
      self.age = 0
  def birthday(self): 
      self.age += 1

alice = Human() #runs constructor
alice.birthday()
alice.birthday()
print(alice.age) #prints 2