Computer Science 1026A/B Lecture Notes - Local Variable, Object-Oriented Programming, Global Variable

14 views16 pages
terubarenuka and 39895 others unlocked
COMPSCI 1026A/B Full Course Notes
26
COMPSCI 1026A/B Full Course Notes
Verified Note
26 documents

Document Summary

Let"s see how we can create a very basic class in python. # create class attributes name = "c200" make = "mercedez" model = 2008. # create class methods def start(self): print ("engine started") def stop(self): print ("engine switched off") Let"s create an object of the car class that we created in the last section. # creates car_a object of car class car_a = car() # creates car_b object of car class car_b = car() we can use the type method and pass it the name of our object. Execute the following script: print(type(car_b)) we call the start() method via the car_b object. car_b. start() you will see the value of the model attribute, print(car_b. model) class car: # create class methods def start(self, name, make, model): print ("engine started") self. name = name self. make = make self. model = model. Car. car_count += 1 car_a = car() car_a. start("corrola", "toyota", 2015) print(car_a. name) print(car_a. car_count)

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents

Related Questions