Tuples: Composed of simple groups of objects
Characteristics:
1. An ordered set of arbitrary objects
2. Access by offset
3. Immutable sequence Type
4. Fixed-length, heterogeneous, arbitrary nesting
5. Array of object references
| Operation |
Explain |
| () |
Empty tuple |
| t= (0,) |
Tuple of a single element |
| T=0, ' a ', 1.2,3 |
4 Elements of a tuple |
| t= (' A ', (' A ', ' B ')) |
Nested tuples |
| T=tuple (' a ') |
Can iterate over objects |
| T[i] |
Index |
| T[I][J] |
Index of Index |
| T[I:J] |
Sharding |
| Len (t) |
Length |
| T1+t2 |
Merge |
| T*3 |
Repeat |
| For x in T:print (x) |
Iteration |
| ' A ' in t |
Member relationships |
| [x**2 for x in T] |
Iteration |
| T.index (' a ') |
Search |
| T.count (' a ') |
Count |
2. Basic operation
The operations of merging, repeating, nesting, sharding, and indexing are reflected in the following code
3. Sorting
By converting tuples into lists, and then calling list methods to sort operations
Generating tuples with list parsing
Why is there a list and a tuple?
Because the tuple's non-modifiable, because the tuple is not modifiable, he as a parameter when passed, do not always pay attention to the consistency of data
Right here, thank you.
------------------------------------------------------------------
Click to jump 0 basic python-Catalogue
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
0 Basic python-9.1 tuples