通过for循环和range打印出下面列表的索引,另外利用while循环如何实现? 比如:li = ["alex", "WuSir", "ritian", "barry", "wenzho"]
时间: 2023-11-09 09:09:49 浏览: 99
利用Python循环(包括while&for)各种打印九九乘法表的实例
利用for循环和range打印出下面列表的索引的代码如下:
```
li = ["alex", "WuSir", "ritian", "barry", "wenzho"]
for i in range(len(li)):
print(i)
```
利用while循环实现的代码如下:
```
li = ["alex", "WuSir", "ritian", "barry", "wenzho"]
i = 0
while i < len(li):
print(i)
i += 1
```
阅读全文