课程内容更新

This commit is contained in:
LSGOMYP
2020-08-01 18:21:09 +08:00
committed by MuXiaQingFeng
parent dee658467d
commit a8c53ef4db
2 changed files with 15 additions and 5 deletions

View File

@@ -404,7 +404,7 @@ print(n) # 120
def factorial(n):
if n == 1:
return 1
return n * fact(n - 1)
return n * factorial(n - 1)
print(factorial(5)) # 120

View File

@@ -154,7 +154,6 @@ b.kick()
# 我叫球B,该死的,谁踢我...
```
---
## 3. Python 的魔法方法
@@ -534,9 +533,11 @@ c = A()
【例子】
```python
class A():
a = xx #类属性
def __init__(self):
A.a = xx #使用类属性可以通过 (类名.类属性)调用。
a = 0 # 类属性
def __init__(self, xx):
# 使用类属性可以通过 (类名.类属性)调用。
A.a = xx
```
@@ -859,6 +860,15 @@ print(cc.x)
1、以下类定义中哪些是类属性哪些是实例属性
```python
class C:
num = 0
def __init__(self):
self.x = 4
self.y = 5
C.count = 6
```
2、怎么定义私有⽅法
3、尝试执行以下代码并解释错误原因