From a8c53ef4db68e62c19ef256affd97e30bd0c0afd Mon Sep 17 00:00:00 2001 From: LSGOMYP Date: Sat, 1 Aug 2020 18:21:09 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=86=85=E5=AE=B9=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PythonLanguage/12. 函数与Lambda表达式.md | 2 +- PythonLanguage/13. 类与对象.md | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) 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、尝试执行以下代码,并解释错误原因: