1 # x='global'
2 class LuffyStudent:
3 school = 'luffycity'
4
5 def __init__(self,name,age,sex):
6 # print(self.__dict__)
7 self.name=name
8 self.age=age
9 self.sex=sex
10 # print(self.__dict__)
11 # print(self.name,self.age)
12
13 def learn(self,data):
14 print('%s is learning'%self.name,data)
15 print(self.name,self.age)
16
17 def eat(self):
18 print('is eatting')
19
20 # print('定义的时候就运行了!')
21
22 # stu1 = LuffyStudent # 类
23 # stu2 = LuffyStudent() # 对象
24 # print(stu1) # <class '__main__.LuffyStudent'>
25 # print(stu2) #<__main__.LuffyStudent object at 0x00000225DEDD3F98>
26 # print(stu2.school) # luffycity
27 # stu2.learn() # is learning
28
29 # print(LuffyStudent.__dict__)
30 # print(LuffyStudent.school)
31 # LuffyStudent.name='alice'
32 # print(LuffyStudent.__dict__['school'])
33 # # print(LuffyStudent.__dict__)
34 # print(LuffyStudent.name)
35 # del LuffyStudent.school
36 # print(LuffyStudent.__dict__)
37 # LuffyStudent.school='Luffy'
38 # print(LuffyStudent.school)
39 # print(LuffyStudent.learn)
40
41 # stu4=LuffyStudent()
42 # print(stu4.__dict__)
43 # print(stu4.school)
44
45 # stu3=LuffyStudent('alice',12)
46 # print(stu3.school,stu3.name,stu3.age)
47 # stu3.learn()
48 # print(stu3.__dict__)
49 # print((stu3.name,stu3.school,stu3.learn))
50 # stu3.sex='female'
51 # print(stu3.__dict__)
52 # print(stu3.sex)
53 # del stu3.__dict__['name']
54 # del stu3.school
55 # print(stu3.__dict__)
56 # stu3.name='aaaa'
57 # print(stu3.__dict__)
58 # print(stu3.name,stu3.age,stu3.sex,stu3.school)
59 # stu3.school='Luffy'
60 # print(stu3.__dict__)
61 # print(stu3.school)
62
63 # stu1=LuffyStudent('alice',12)
64 # stu2=LuffyStudent('alex',18)
65 # print(stu1.__dict__)
66 # # stu1.school='luffy'
67 # print(stu1.school,stu1.name)
68 # print(id(stu1.school),id(stu2.school))
69 # print(stu1.school is stu2.school)
70 # print(stu1.learn,stu2.learn)
71 # print(stu1.learn is stu2.learn)
72 # stu1.learn()
73
74 # stu1.learn(3)
75 # LuffyStudent.learn(stu1,5)
76
77 # stu1.scho='luffy'
78 # print(stu1.scho)
79 # LuffyStudent.x='xxx'
80 # print(LuffyStudent.__dict__)
81 # stu1.x='sss'
82 # print(stu1.x)
83
84 # li = list([1,2,3,4])
85 # li.append(5)
86 # print(li)
87 # dic=dict({'name':'alice'})
88 # dic['age']=12
89 # print(dic)
90 # dict.setdefault(dic,'sex','female')
91 #
92 # print(dic)
93 # print(type(list))
94 #
95 # li=list([1,2,3,4])
96 # print(li)
97 # li.append(5)
98 # list.append(li,6)
99 # print(li)
100
101 stu1=LuffyStudent('alice',12,'female')
102 print(stu1.sex)