From f2ab1168ff7709d188a7966a141729472855178b Mon Sep 17 00:00:00 2001 From: wsb <110@qq.com> Date: Tue, 9 May 2023 17:15:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0python=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E8=AF=AD=E6=B3=95=E5=AD=A6=E4=B9=A0=E7=AC=94=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...5\260\346\215\256\347\273\223\346\236\2042.py" | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git "a/\346\225\260\346\215\256\347\273\223\346\236\2042.py" "b/\346\225\260\346\215\256\347\273\223\346\236\2042.py" index f1bce33..e92acae 100644 --- "a/\346\225\260\346\215\256\347\273\223\346\236\2042.py" +++ "b/\346\225\260\346\215\256\347\273\223\346\236\2042.py" @@ -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) + + + -- GitLab