8000 class variables · ammarlodhi255/python-src@83cded7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 83cded7

Browse files
committed
class variables
1 parent edf70d5 commit 83cded7

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

OOP/class_variables.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Car:
2+
3+
num_of_chairs = 4 # Class Variable
4+
5+
def __init__(self, color, model, speed):
6+
self.color = color
7+
self.model = model
8+
self.speed = speed
9+
10+
def show_details(self):
11+
print(
12+
f'Color: {self.color}\nSpeed: {self.speed}\nModel: {self.model}\n')
13+
14+
def show_num_of_chairs(self):
15+
print(Car.num_of_chairs) # Access class variable
16+
17+
18+
car = Car('blue', 'OP90', '190mph')
19+
# Let us see the instance variable of this object:
20+
print(car.__dict__)

0 commit comments

Comments
 (0)
0