forked from WilliamQLiu/python-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclassobjects.py
More file actions
29 lines (25 loc) · 803 Bytes
/
classobjects.py
File metadata and controls
29 lines (25 loc) · 803 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
""" How to use Python's Class and Object"""
# Class is CarClass(), which is basically a template
# car1 and car2 are Objects from Class CarClass()
class CarClass():
""" The template for cars, has own attributes """
cartype="stuff"
name = "blah"
worth = 1000
def report_back(self):
print "Car type is: ", self.cartype
print "Car name is: ", self.name
print "Car worth is: ", self.worth, "\n"
if __name__ == '__main__':
# Create first object, then assign attributes
car1 = CarClass()
car1.cartype="red convertible"
car1.name="Fer"
car1.worth=60000
car1.report_back()
# Create second object, then assign attributes
car2 = CarClass()
car2.cartype="blue van"
car2.name="Jump"
car2.worth=10000
car2.report_back()