The usage of tuples in python

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

The usage of tuples in python
The usage of wheel in python
The usage of Ajax in Python3 crawler
Subscripts of tuples in Python
The meaning and usage of lists in python
Detailed usage of dictionary in Python
Usage of os package in python
Understanding the meaning of rb in python
MongoDB usage in Python
The usage of several regular expressions in Linux
Python implements the shuffling of the cards in Doudizhu
The usage of several regular expressions in Linux
Detailed explanation of the usage of Python decimal module
The usage of several regular expressions in Linux
The consequences of uninstalling python in ubuntu, very
Consolidate the foundation of Python (4)
Consolidate the foundation of Python(7)
Consolidate the foundation of Python(5)
How to understand the introduction of packages in Python
Summary of logarithm method in Python
Analysis of usage examples of Python yield
Use of Pandas in Python development
Learn the hard core operation of Python in one minute
Python handles the 4 wheels of Chinese
Use of numpy in Python development
Python simulation of the landlord deal
What is the use of Python
Simple usage of python definition class
Talking about the modules in Python
The premise of Python string pooling
Secrets of the new features of Python 3.8
The father of Python joins Microsoft
The operation of python access hdfs
End the method of running python
Description of in parameterization in python mysql
Can Python implement the structure of the stack?
Learn the basics of python interactive mode
What are the required parameters of python
Implementation of JWT user authentication in python
Logistic regression at the bottom of python
Python solves the Tower of Hanoi game
Solve the conflict of multiple versions of python
What is the scope of python variables
Python implements the sum of fractional sequences
Two days of learning the basics of Python
Analysis of glob in python standard library
Where is the pip path of python3
Method of installing django module in python
The essence of Python language: Itertools library
What are the advantages of python language
python3 realizes the function of mask drawing
What is the prospect of python development
Detailed usage of Python virtual environment venv
What is the function body of python
Knowledge points of shell execution in python
The specific method of python import library
Solve the conflict of multiple versions of python
Python randomly shuffles the elements in the list
Functions in python
Detailed explanation of the use of pip in Python | summary of third-party library installation
2.1 The Python Interpreter (python interpreter)