我是Python的新手.
说我有一个清单:
list = ['A','B','C','D']
Run Code Online (Sandbox Code Playgroud)
这里每个项目的关键是0,1,2,3 - 对吗?
现在我将使用for循环遍历它...
for item in list:
print item
Run Code Online (Sandbox Code Playgroud)
那很好,我可以打印出我的清单.
我如何在这里获得密钥?例如,能够做到:
print key
print item
Run Code Online (Sandbox Code Playgroud)
在每个循环?
如果列表无法做到这一点,那么自己不会声明键,是否可以使用词典?
谢谢
friends = ["John", "Mark", "James"]
for friend in friends:
print(friend)
Run Code Online (Sandbox Code Playgroud)
如何使用 for 循环打印此列表中的第二个元素?我知道如何获取列表中的第二个元素,但我不知道如何使用for循环获取它。
python ×2