Skip to content

Commit 2cbc021

Browse files
committed
使用字典存储动态变量
1 parent 5537a9b commit 2cbc021

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

create_variable.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""
2+
演示Python如何动态创建变量
3+
"""
4+
5+
pages = {}
6+
7+
for page in range(1, 50):
8+
"""
9+
这里想创建变量page1 = 1, page2 = 2, page3 = 3,...
10+
"""
11+
pages[page] = page
12+
13+
print(pages[1])
14+
print(pages[2])

0 commit comments

Comments
 (0)