码迷,mamicode.com
首页 > 其他好文 > 详细

10.for

时间:2018-12-30 11:42:55      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:测试   locate   dsc   字典   array   statement   with   var   line   

要遍历一个范围(如数组或表),使用 for 循环。在数组上迭代时,当前数组元素存储在循环变量中。在遍历字典时, index 存储在循环变量中。

(in 内容测试)

for x in [5, 7, 11]:
    statement # Loop iterates 3 times with ‘x‘ as 5, then 7 and finally 11.

var dict = {"a": 0, "b": 1, "c": 2}
for i in dict:
    print(dict[i])

for i in range(3):
    statement # Similar to [0, 1, 2] but does not allocate an array.

for i in range(1,3):
    statement # Similar to [1, 2] but does not allocate an array.

for i in range(2,8,2):
    statement # Similar to [2, 4, 6] but does not allocate an array.

for c in "Hello":
    print(c) # Iterate through all characters in a String, print every letter on new line.

10.for

标签:测试   locate   dsc   字典   array   statement   with   var   line   

原文地址:https://www.cnblogs.com/empist/p/10198816.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!