Python Basics-Immutable sequences: tuples

Source: Internet
Author: User

Life goes beyond Python!

The previous blog share with you a list of the drudgery in Python. There are many things we can do to modify the list.

What we are going to share today is another sequence, but it cannot be modified, that is, the tuple, which is enclosed in parentheses .

Separate values with commas, automatically creating tuples

>>>1, 2, 3(1, 2, 3)

Empty tuple

>>>()()

A tuple that contains a value that must be comma-

>>>3333>>>(33)33>>>33,(33,)

tuple function
Basically the same as the list function: Takes a sequence as an argument and converts it to a tuple, or returns if the argument is a tuple.

>>>tuple([123])(123)>>>tuple(‘abc‘)(‘a‘‘b‘‘c‘)>>>tuple((123))(123)

Meta-Group Index

>>>x = 1, 2, 3>>>x[1]1

tuple Shards
End of Shard or tuple

>>>x = 1, 2, 3>>>x[0:2](1, 2)

why the existence of tuples
1 can be used as keys in the map
2 many built-in functions and methods use tuples as return values

Python Basics-Immutable sequences: tuples

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.