Python Class Example

PHOTO EMBED

Sun Aug 22 2021 20:15:15 GMT+0000 (Coordinated Universal Time)

Saved by @mcdave #python #ooo

class Band:
 
  bandcount = 0
 
  def __init__(self, name, instrument): #these are attributes
          self.name = name
          self.instrument = instrument
          Band.bandcount += 1
 
  def displayInstrumnet(self): #this is a method
          print(self.name, "plays", self.instrument)
 
  def bandCount(self):
          print("# of Bandmembers = ", Band.bandcount)
content_copyCOPY

method = a function in a class, needs the () - need to put `self` in the method () attribute =