Python built-in functions (64) -- tuple, python built-in 64 tuple
English document:
The constructor builds a tuple whose items are the same and in the same orderIterable'S items.IterableMay be either a sequence, a container that supports iteration, or an iterator object. IfIterableIs already a tuple, it is returned unchanged. For example,tuple('abc')
Returns('a', 'b', 'c')
Andtuple( [1, 2, 3] )
Returns(1, 2, 3)
. If no argument is given, the constructor creates a new empty tuple,()
.
Note:
1. The function creates a new tuple.
2. If no Parameter Function is input, an empty tuples will be created.
# If no parameter is input, create an empty tuples >>> tuple ()()
3. The function can receive one iteratable object as a parameter. A new tuples will be created using each element of the iteratable object.
# Input non-iteratable object, cannot create new tuples >>> tuple (121) Traceback (most recent call last): File "<pyshell #17>", line 1, in <module> tuple (121) TypeError: 'int' object is not iterable # Pass in the iteratable object. Use its elements to create new tuples >>> tuple ('000000') ('1', '2', '1') >>> tuple ([121, 1]) (1, 2, 1) >>> tuple (1, 1) (1, 2, 1)
4. You can also use a pair of parentheses to create new tuples:
4.1 use a pair of parentheses to create empty tuples.
>>> a= ()>>> a()
4.2 When creating a single element's tuples, it must be followed by a comma.
>>> A = (1,) >>> a # a is a tuple (1,) >>> a = (1) >>> a # a is a value of 1
4.3 create tuples for multiple elements, which are separated by commas.
>>> a = (1,2,3)>>> a(1, 2, 3)