09-15-周一_11-25-51

This commit is contained in:
2025-09-15 11:25:51 +08:00
parent 4a83558acd
commit 257e88d79f
5 changed files with 23 additions and 23 deletions

View File

@@ -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()
```

View File

@@ -98,7 +98,7 @@ print(Person.type_name)
Person.eat('东西')
print(Person.type_name)
p1 = Person('aaron','男',18)
p1 = Person('张三','男',18)
print(p1.__dict__)
print(p1.type_name)
p1.type_name = '666'
@@ -131,7 +131,7 @@ class Cat(Aniaml):
class Dog(Aniaml):
pass
p1 = Person('eagle','男',18)
p1 = Person('张三','男',18)
p1.eat()
```
@@ -164,7 +164,7 @@ class Cat(Aniaml):
class Dog(Aniaml):
pass
p1 = Person('aaron','男',18,'想吃东西')
p1 = Person('张三','男',18,'想吃东西')
p1.eat()
```
@@ -196,7 +196,7 @@ class Cat(Aniaml):
class Dog(Aniaml):
pass
p1 = Person('aaron','男',18,'想吃东西')
p1 = Person('张三','男',18,'想吃东西')
p1.eat()
```

View File

@@ -20,8 +20,8 @@ class Foo:
self.name = name
self.age = age
obj1 = Foo('chensong',18)
obj2 = Foo('aaron',16)
obj1 = Foo('张三',18)
obj2 = Foo('李四',16)
```
第二步:从某处调用被封装的内容
@@ -36,8 +36,8 @@ class Foo:
print(self.name)
print(self.age)
obj1 = Foo('chensong',18)
obj2 = Foo('aaron',16)
obj1 = Foo('张三',18)
obj2 = Foo('李四',16)
print(obj1.name)
print(obj2.age)

View File

@@ -311,9 +311,9 @@ class Student:
return cls.__num
Student('陈松', 18)
Student('阿松', 36)
Student('松松', 73)
Student('张三', 18)
Student('李四', 36)
Student('王五', 73)
print(Student.getNum())
```
@@ -370,7 +370,7 @@ class People:
def bmi(self):
return self.weight / (self.height**2)
p1=People('陈松',75,1.85)
p1=People('张三',75,1.85)
print(p1.bmi)
```

View File

@@ -20,7 +20,7 @@ class Foo:
def say_hi(self):
print('hi,%s'%self.name)
obj=Foo('陈松',73)
obj=Foo('张三',73)
# 检测是否含有某属性
print(hasattr(obj,'name'))
@@ -55,7 +55,7 @@ class Foo(object):
staticField = "test"
def __init__(self):
self.name = '陈松'
self.name = '张三'
def func(self):
return 'func'
@@ -293,7 +293,7 @@ class A:
def __init__(self):
pass
def __str__(self):
return '陈松'
return '张三'
a = A()
print(a)
print('%s' % a)
@@ -308,7 +308,7 @@ class A:
def __init__(self):
pass
def __repr__(self):
return '陈松'
return '张三'
a = A()
print(repr(a))
print('%r'%a)