Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

classes in python

# plz suscribe to my youtube channel -->
# https://www.youtube.com/channel/UC-sfqidn2fKZslHWnm5qe-A

class Fan:

    def __init__(self, company, color, number_of_wings):
        self.company = company
        self.color = color
        self.number_of_wings = number_of_wings
        
    def PrintDetails(self):
        print('This is the brand of',self.company,'its color is', self.color,' and it has',self.number_of_wings,'petals')
    
        
    def switch_on(self):
        print("fan started")
        
    def switch_off(self):
        print("fan stopped")
        
    def speed_up(self):
        print("speed increased by 1 unit")
        
    def speed_down(self):
        print("speed decreased by 1 unit")
        
usha_fan = Fan('usha','skin',5)
fan = Fan('bajaj','wite', 4)


print('these are the details of this fan')
usha_fan.PrintDetails()
print()

usha_fan.switch_on()
Source by codefreelance.net #
 
PREVIOUS NEXT
Tagged: #classes #python
ADD COMMENT
Topic
Name
4+3 =