09-15-周一_11-25-51
This commit is contained in:
@@ -169,8 +169,8 @@ class Human:
|
||||
def work(self):
|
||||
print(self,'会工作')
|
||||
|
||||
Human.work('chensong')
|
||||
Human.__dict__['work']('chensong')
|
||||
Human.work('张三')
|
||||
Human.__dict__['work']('张三')
|
||||
```
|
||||
|
||||
## 从对象的角度研究类
|
||||
@@ -210,7 +210,7 @@ class Human:
|
||||
self.a = age
|
||||
self.h = hobby
|
||||
|
||||
obj = Human('chensong','男','18','男')
|
||||
obj = Human('张三','男','18','男')
|
||||
```
|
||||
|
||||
### 对象操作对象空间属性
|
||||
@@ -229,7 +229,7 @@ class Human:
|
||||
self.a = age
|
||||
self.h = hobby
|
||||
|
||||
obj = Human('chensong','男',18,'男')
|
||||
obj = Human('张三','男',18,'男')
|
||||
print(obj.__dict__)
|
||||
```
|
||||
|
||||
@@ -247,7 +247,7 @@ class Human:
|
||||
self.a = age
|
||||
self.h = hobby
|
||||
|
||||
obj = Human('chensong','男',18,'男')
|
||||
obj = Human('张三','男',18,'男')
|
||||
obj.job = 'IT'
|
||||
del obj.n
|
||||
obj.s = '女'
|
||||
@@ -269,7 +269,7 @@ class Human:
|
||||
self.a = age
|
||||
self.h = hobby
|
||||
|
||||
obj = Human('chensong','男',18,'男')
|
||||
obj = Human('张三','男',18,'男')
|
||||
print(obj.mind)
|
||||
print(obj.language)
|
||||
obj.a = 666
|
||||
@@ -297,7 +297,7 @@ class Human:
|
||||
def tools(self):
|
||||
print(self.n,'会使用工具')
|
||||
|
||||
obj = Human('chensong','男',18,'男')
|
||||
obj = Human('张三','男',18,'男')
|
||||
obj.work()
|
||||
obj.tools()
|
||||
```
|
||||
|
Reference in New Issue
Block a user