Python Base---container tuple

Source: Internet
Author: User

Tuple tuples

Definition: The element within the container is immutable, the container is a tuple

Use () to represent a tuple

After the tuple is initialized, its elements are not modifiable and cannot be deleted

To create a tuple:

1, x = (obj1, obj2, Obj3,...) or x = Obj1, Obj2, Obj3, ...

1 x = (1, 2, 3, 4, 5)2print(x, type (x))3 ---> (1, 2, 3, 4, 5) < class ' tuple '>

2, x = () Create an empty tuple

1 x = ()2print(x, type (x))3 ---> () <class'  tuple'>

Built-in functions:

1. Len (tuple) Gets the length of a tuple

2, Max (tuple) & min (tuple) Gets the maximum and minimum values for a tuple

3. Tuple (SEQ) converts a list to a tuple

1 list = [1, 2, 3, 4, 5]2 tup = tuple (list)3print(tup) 4 ---> (1, 2, 3, 4, 5)

Tuple tuples, as a sequence container, are the same as list lists, with:

1. Slicing operation

2. Connection +

3. Copy *

4. Member detection in & not in

5. For ... in ... Looping through

Tuple derivation formula:

tuple = (n for n in list if judging condition)

1 tup1 = (1, 2, 3, 4, 5)2 for in tup1)3print  (Tup2, type (tup2)) 4 ---><generator object <genexpr> at 0x05672e70> <class'  Generator'>

The tuple derived from the tuple is actually a generator

Python Base---container tuple

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.