我的想法
Tuple 是 Python 里的一个重要的基本概念
常见的表达形式:
3,5,7,11思考和 List 的区别。
In Python, it is a sequence of values separated by commas(逗号)
nums = (1, 2, 3, 4, 5)The fact is that we even don’t need to use commas.
It is quite similar to Array in C, if we scan:
print(nums[0])Its output will be 1, because there index numbers start at 0. (that is the similarity)
In the same tuple, the elements type could not be the same.
Note that the element in a tuple could not change! That means that if we print:
nums = 1,2,3,4,5
nums[0] = 3It will occur an error ! This is different from Array in C
Difference to List
- Tuples are faster
- Tuple can’t be changed, so when we know the data won’t change, it could be efficient and can protect from being changed
- “It can be used as keys in a dictionary, while list can’t”(这段话是 PPT 里的,但是不太清楚啥意思)