Python basics-Introduction to tuples of immutable sequences

Source: Internet
Author: User

Python basics-Introduction to tuples of immutable sequences

More than Python!

In the previous blog, I shared with you the effort and list in Python. We can modify the list through many operations.

Another sequence is to be shared today, but it cannot be modified, that is, the tuples, which areEnclose in parentheses.

Values are separated by commas (,), and tuples are automatically created.

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

Empty tuples

>>>()()

The tuples that contain a value must contain commas (,).

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

Tuple Function
Basically the same as the list function: uses a sequence as a parameter and converts it to a tuple. If the parameter is a tuple, it is returned as is.

>>>tuple([1, 2, 3])(1, 2, 3)>>>tuple('abc')('a', 'b', 'c')>>>tuple((1, 2, 3))(1, 2, 3)

Tuples Index

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

Tuples
Whether the parts are finished or the tuples

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

Why are there tuples?
1 can be used as a key in ing
2 many built-in functions and methods use tuples as return values

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.