Python Tuple (tuple) tuple () method
description
Python tuple tuple () function converts a list of tuples.
grammar
tuple () method syntax:
tuple( seq )
parameter
- seq - to be converted into a sequence of tuples.
return value
Returns the minimum tuple elements.
Examples
The following example shows the tuple () function to use:
Example 1:
>>> tuple([1,2,3,4]) (1, 2, 3, 4) >>> tuple({1:2,3:4}) #针对字典 会返回字典的key组成的tuple (1, 3) >>> tuple((1,2,3,4)) #元组会返回元组自身 (1, 2, 3, 4)
Example 2:
#!/usr/bin/python aList = [123, 'xyz', 'zara', 'abc']; aTuple = tuple(aList) print "Tuple elements : ", aTuple
The above example output is:
Tuple elements : (123, 'xyz', 'zara', 'abc')