What does python tuple mean?

藏色散人
Release: 2019-06-25 11:52:58
Original
11998 people have browsed it

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 )
Copy after login

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)
Copy after login

Example 2

#!/usr/bin/python
 
aList = [123, 'xyz', 'zara', 'abc'];
aTuple = tuple(aList)
 
print "Tuple elements : ", aTuple
Copy after login

The output result of the above example is:

Tuple elements :  (123, 'xyz', 'zara', 'abc')
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template