Tuple: There are only two operable functions [count()/index()] inside the tuple, one is to view the total number of data in the tuple and the other is to view.
The position of a data in the tuple, there is an external default function sorted to sort the tuple, sorting note: use the system default sort, but must ensure that the sorted data and their data types are consistent! Functions related to tuple query can be directly operated, such as: len() to view the number of elements in the tuple.
Declaration tuple way
Name =tuple()
name =(“1”,”2”,”3”)
name =(“1”,)name(1,)
Count()
View the number of occurrences of a certain data
Index()
Where to view the data
Knowledge point expansion:
The difference between tuples and lists
(1) The list is mutable, and the tuple is immutable, unless the whole is replaced.
(2) The list can be added and deleted with append(), extend(), insert(), remove(), pop(), but tuples do not have these methods.
(3) The list supports modification and access through trimming, while tuples only support access, not modification. When no modification is required, it is recommended to use tuples.
(4) Tuples are faster to access and process than lists.
(5) Lists cannot be used as dictionary keys, but tuples can.
The above is the detailed content of the usage of tuples in python. For more information on how to use tuples in python, please pay attention to other related articles on ZaLou.Cn!
Recommended Posts