In this article we discuss tuples, ordered and unchangeable (read-only) data types. It may have the same or different data type elements and is indicated in brackets ().
Syntax:
t = (1,2,0.5, jki’, hi’.6)
We must be particularly careful when proclaiming a procession with an element.
If you leave out a comma (,) here, it’s a common whole variable.
The first example is a motorcade.
In the second example, the type is integer.
Another way to announce the procession:
How do I become a member of the Python Translator Group?
Open the Linux terminal and type Python, then press enter, and we will see a Python interpreter. For the version of python3+, like Python3, here is the following information, which we will see in the terminal If we want to check the version of python, choose python -v.
A way out:
Python 3.5.0 (default, September 20, 2019, 11:28:25)
[GCC 5.2.0] on Linux
For more information you can provide a reference, copyright, credits or license.
The following operations can be performed by the procession:
Disk of an engine bay
It’s useful if we only need part of the motorcade.
Pay attention: The autocorso index always starts at 0. The car column can be moved forwards and backwards (using the negative index).
For example:
t = (1,2,3,4,hi, good, 10,5)
Progress index : 0,1,2,3…]
Index of Invert: [… -3,-2,-1] here t[-1]=10,5, t[-2]=good,
t[-3]=good, t[-4]=4,….
Syntax:
Variable name [Start:Stop:Step].
We can’t stop here. If only the beginning is specified, all elements are extracted from the beginning to the end of the procession. If we specify only one stop, it will be taken out of the index from 0 to stop. We can skip both start and stop, in which case we have to specify at least one colon (t[:]). If we do not specify a default step value, the value is 1.
An ex:
t = (1,2,3,4,5, and, hello, 10,5)
In this example we want to extract the elements 1,2,3,4.
Suppose we want to extract elements 3, 4, 5 and, hey, 10, 5.
Suppose we want to extract the elements 2,3,4,5, I, Hi (using the reverse index).
Suppose we want to turn the motorcade around.
Nested tuples
We can announce a procession within a procession, i.e. a nested procession.
t = (1,2, (3,4,5),6,7, (a, b, c))
Consider a nested parade as another parade, and its index also starts at 0.
We have access to the nested tuples as shown below:
- Find the subscript of the most important tuple
- Find the Tuple subscription
An ex:
In the following example, we want to take 3 out of the self nested column. Here the main tuple index is t[2], and the nested tuple (3.4.5) is 0. So the last expression is t[2][0].
In the second example we took b from the attached tuple with the expression t[5][1].
Length
This method shows the number of elements in the motorcade.
Syntax:
Access to vehicle convoy by hinges
Syntax:
For the variable in the procession:
Repeat
It is useful if you want to repeat the parade for a number of vehicles.
Syntax:
variable * Number of repetitions
For example:
Here the motorcade is repeated twice, as shown below.
Concentration
It is a concatenation or combination of two motorised hoists.
Syntax:
Cortex search element
The answer will be true if the object found in the procession is returned as False. Incoming and outgoing members are not used to verify this.
Syntax:
Element in line of vehicles Element not in line of vehicles
Index
This method is used to find the index of an article in a procession. If the found copy is returned as an element index, an exception is made via the value error.
Syntax:
variable.index(element, beg=0,end=len(string))
Column
This method is used to calculate the presence of an element in a procession.
Syntax:
Clear the engine bay
We cannot remove the individual elements from the tuples because they are invariable. But we can remove the entire motorcade.
Syntax:
In the above example we explained the procession t and printed t. Then we removed the tuple with del t and tried to print the tuple. He makes an exception to call it terror, because there is no motorcade.
Minimum
This method is used to find the minimum value of an element in an engine column.
Syntax:
Maximum
This method is used to find the minimum value of an element in an engine column.
Syntax:
Compare 2 tuples
This method is used to compare the elements of 2 tuples.
- Returns 0 if the elements of both tuples are equal.
- Returns 1 if the elements of the first tuple are larger than those of the second tuple.
- Returns -1 if the elements of the first tuple are smaller than those of the second tuple.
Syntax:
If the element types do not match, the element is converted to type int.
Tuples are compared using clues. The first element of the first tuple is compared to the first element of the second tuple. If they are not identical, it is the result of an equation, otherwise the 2. third element is taken into account.
Conclusion
Tuple is an invariable data type and each operation we perform must be stored in a different variable tuple. It is faster than other types of data (e.g. list, dictionary). Since the tuple is immutable in our program, the data will not change during the entire life cycle of the software, we can use both the tuple and the system configuration data.
This is the most common and widely used operation in a motorcade. If we want to check which operations are supported for tuple, type dir(tuple) on the interpreter and press enter. All methods/functions are displayed. If we want to check the documentation of the tuple method/function, type help(tuple) and press Enter.
Related Tags:
python practice sets,8.1.8: citation,dictionary programs in python,python slicing exercises,how to remove duplicates from tuple in python,write a python program to reverse a tuple.,python type() function,vscode python type checking,python runtime type checking,python3.6 static typing,python uses duck typing,python/mypy