Python 中的 List、Dictionary 和 Tuple 之间有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3649841/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What are differences between List, Dictionary and Tuple in Python?
提问by Ibrahim Nattaj
What is the difference between list, dictionary and tuple in Python exactly?
Python 中的列表、字典和元组到底有什么区别?
回答by Mark Byers
A list can store a sequence of objects in a certain order such that you can index into the list, or iterate over the list. List is a mutable type meaning that lists can be modified after they have been created.
列表可以按特定顺序存储一系列对象,以便您可以对列表进行索引,或遍历列表。List 是一种可变类型,这意味着列表可以在创建后进行修改。
A tuple is similar to a list except it is immutable. There is also a semantic difference between a list and a tuple. To quote Nikow's answer:
元组类似于列表,但它是不可变的。列表和元组之间也存在语义差异。引用Nikow 的回答:
Tuples have structure, lists have order.
元组有结构,列表有顺序。
A dictionary is a key-value store. It is not ordered and it requires that the keys are hashable. It is fast for lookups by key.
字典是键值存储。它不是有序的,它要求键是可散列的。按键查找速度很快。

