-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathch15_class.py
More file actions
60 lines (44 loc) · 994 Bytes
/
ch15_class.py
File metadata and controls
60 lines (44 loc) · 994 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
print(dir(__builtins__))
print('\n')
x = 1
copyright = 'This is the global copyright.'
print(x)
print(copyright)
print(globals())
print(locals())
print('\n')
class Student:
x = 2
copyright = 'This is the class copyright.'
print(x)
print(copyright)
print(globals())
print(locals())
print('\n')
def __init__(self, name, age):
self.name = name
self.age = age
# global x, copyright
x = 3
copyright = 'This is the init copyright.'
print('Student(name={}, age={})'.format(self.name, self.age))
print(x)
print(copyright)
print(globals())
print(locals())
print('\n')
def say(self):
x = 4
copyright = 'This is the self copyright.'
print(x)
print(copyright)
print(globals())
print(locals())
print('\n')
s1 = Student('Jack', 20)
s1.say()
print(x)
print(copyright)
print(globals())
print(locals())
print('\n')