Skip to content

Commit fdacefd

Browse files
committed
docs: 添加文档
1 parent 992afbf commit fdacefd

3 files changed

Lines changed: 45 additions & 0 deletions

File tree

889 KB
Binary file not shown.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
- [内置函数](./built-in-functions.md)
5353
- [](./class.md)
5454
- [类属性、实例属性](./class-instance-props.md)
55+
- [类的属性与方法](./functions-props.md)
5556
- [__slots__](./slots.md)
5657
- [@property](./@property.md)
5758
- [定制类](./custom-class.md)

functions-props.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# 类的属性与方法
2+
3+
- `` 属性
4+
```python
5+
class T:
6+
props = None # 这个就是类属性
7+
```
8+
- `实例` 属性
9+
```python
10+
t = T()
11+
t.props = 1 # 实例属性
12+
```
13+
14+
注: 通过实例访问属性时,如果 **实例对象没有找到**,会 “向上查找” `类属性`
15+
16+
----
17+
18+
- `类方法`
19+
```python
20+
class T:
21+
@classmethod
22+
def method(cls): # cls: Python 自动添加当前类引用
23+
pass
24+
25+
T.method()
26+
```
27+
- `实例方法`
28+
```python
29+
class T:
30+
def method(self):
31+
pass
32+
33+
t = T()
34+
t.method()
35+
```
36+
- `静态方法`
37+
```python
38+
class T:
39+
@staticmethod
40+
def method():
41+
pass
42+
43+
T.method()
44+
```

0 commit comments

Comments
 (0)