Skip to content

Commit 491c2a6

Browse files
committed
feat: plus equal operation
1 parent 9fd1215 commit 491c2a6

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

codes/advanced_grammar/plus_equal.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
def demo(num, num_list: list):
2+
3+
print("函数开始")
4+
5+
# 数值 等价于:num = num + num,不会影响外部变量
6+
num += num
7+
8+
# 列表变量使用 += 不会做相加再赋值的操作
9+
# 不同于 num_list = num_list + num_list
10+
# 本质上是在调用列表的 extend 方法
11+
# num_list.extend(num_list)
12+
num_list += num_list
13+
print(num)
14+
print(num_list)
15+
16+
print("函数完成")
17+
18+
19+
gl_num = 9
20+
gl_list = [1, 2, 3]
21+
demo(gl_num, gl_list)
22+
print(gl_num)
23+
print(gl_list)

0 commit comments

Comments
 (0)