提交 f2ab1168 编写于 作者: W wsb

增加python基础语法学习笔记

上级 70bf2be1
......@@ -46,3 +46,18 @@ for k, v in dt3.items():
# 在序列中循环时,用 enumerate() 函数可以同时取出位置索引和对应的值:
for i, v in enumerate(dt3):
print(i, v)
#同时循环两个或多个序列时,用 zip() 函数可以将其内的元素一一匹配:
questions = ['name', 'quest', 'favorite color']
answers = ['lancelot', 'the holy grail', 'blue']
for q, a in zip(questions, answers):
print('What is your {0}? It is {1}.'.format(q, a))
#逆向循环序列时,先正向定位序列,然后调用 reversed() 函数:
for i in reversed (range(1,10,2)):
print(i)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册