首页 > 编程语言 >Day6:Python基础:Range与enumerate的区别

Day6:Python基础:Range与enumerate的区别

时间:2022-11-08 11:14:29浏览次数:49  
标签:end Day6 a1 Python Range ls b2 enumerate print

ls = ['a', 'b', 'c']
# method 1
for i in range(len(ls)):
   print(i, end = ' ')
#    print(i)
   print(ls[i])

# method 2
for s in ls:
    print(ls.index(s), end=' ')
    print(s)

# method 3
for i, s in enumerate(ls):
    print(i, end=' ')
    print(s)
=============================================================

0 a
1 b
2 c
0 a
1 b
2 c
0 a
1 b
2 c

 

标签:end,Day6,a1,Python,Range,ls,b2,enumerate,print
From: https://www.cnblogs.com/leishu/p/16868992.html

相关文章