-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclass.py
More file actions
38 lines (28 loc) · 823 Bytes
/
class.py
File metadata and controls
38 lines (28 loc) · 823 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
30
31
32
33
34
35
36
37
38
# What is a class
#
# Python's expression as a type is a class
class Car:
def __init__(self, color):
self.color = color
def drive(self):
print("You are driving the car")
my_car = Car("red")
print(my_car.color)
my_car.drive()
print("type(my_car)", "\n", type(my_car), "\n", 25 * "--", "\n")
print("type(Car)", "\n", type(Car), "\n", 25 * "--", "\n")
print("dir(my_car)", "\n", dir(my_car), "\n", 25 * "--", "\n")
print("my_car.__dict__", "\n", my_car.__dict__, "\n", 25 * "--", "\n")
print("my_car.__class__", "\n", my_car.__class__, "\n", 25 * "--", "\n")
# Mapping Proxy
print(
"my_car.__class__.__dict__", "\n", my_car.__class__.__dict__, "\n", 25 * "--", "\n"
)
print(
"my_car.__class__.__bases__",
"\n",
my_car.__class__.__bases__,
"\n",
25 * "--",
"\n",
)