Home  >  Article  >  Backend Development  >  What does python tuple mean?

What does python tuple mean?

藏色散人
藏色散人Original
2019-06-25 11:52:5811976browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn