diff --git a/PythonLanguage/12. 函数与Lambda表达式.md b/PythonLanguage/12. 函数与Lambda表达式.md index 20d222e..35b1f1e 100644 --- a/PythonLanguage/12. 函数与Lambda表达式.md +++ b/PythonLanguage/12. 函数与Lambda表达式.md @@ -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 diff --git a/PythonLanguage/13. 类与对象.md b/PythonLanguage/13. 类与对象.md index 93fc285..43e9084 100644 --- a/PythonLanguage/13. 类与对象.md +++ b/PythonLanguage/13. 类与对象.md @@ -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、尝试执行以下代码,并解释错误原因: