Home > Article > Backend Development > What does python tuple mean?
What does python tuple mean?
python tuple is a tuple, and the tuple() function converts a list into a tuple.
tuple() method syntax:
tuple( seq )
Parameters
seq -- The sequence to be converted to a tuple.
Return value
Return tuple.
The following examples show how to use the tuple() function:
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 output result of the above example is:
Tuple elements : (123, 'xyz', 'zara', 'abc')
Related recommendations: "Python Tutorial"
The above is the detailed content of What does python tuple mean?. For more information, please follow other related articles on the PHP Chinese website!