开发者

What are differences between List, Dictionary and Tuple in Python? [duplicate]

开发者 https://www.devze.com 2023-01-15 03:27 出处:网络
This question already has answers here: 开发者_如何转开发In Python, when to use a Dictionary, List or Set?
This question already has answers here: 开发者_如何转开发 In Python, when to use a Dictionary, List or Set? (13 answers) Closed 9 years ago.

What is the difference between list, dictionary and tuple in Python exactly?


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.

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:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消