Python built-in functions (64) -- tuple, python built-in 64 tuple

Source: Internet
Author: User

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)

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.