如何访问列表元素 [英] How to access List elements
本文介绍了如何访问列表元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个列表
list = [['vegas','London'],['US','UK']]
如何访问此列表的每个元素?
How to access each element of this list?
推荐答案
我先不调用它list
,因为这是Python内置list
类型的构造函数的名称.
I'd start by not calling it list
, since that's the name of the constructor for Python's built in list
type.
但是一旦将其重命名为cities
或类似的名称,您就可以这样做:
But once you've renamed it to cities
or something, you'd do:
print(cities[0][0], cities[1][0])
print(cities[0][1], cities[1][1])
这篇关于如何访问列表元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文