""" A demonstration of Python class, adapted from course notes by other CSCI 203 instructor(s) Xiannong Meng 2016-10-27 """ class Bird: color = 'Yellow' # class field def __init__( self ): # constructor """ Create an object """ self.weight = 10 # instance field, no units ;0) def __str__( self ): """ The string representation of the object """ return Bird.color + " Hello." def fly( self ): # instance method """ An example of method """ if self.weight > 15: self.lighten_the_load() # execute (or call) another method else: print(Bird.color, " IS FLYING!!!") def lighten_the_load( self ): """ Another example of method """ print('Splat!') self.weight -= 5 def eat( self, food_weight ): """ Another example of method """ self.weight = self.weight + food_weight #sparrow = Bird() #print( sparrow ) #sparrow.fly() #sparrow.eat( 20 ) #sparrow.fly()