Python Basics: Tuple

Source: Internet
Author: User

About 0x00

Tuple (tuple), which is equivalent to the immutable list. Tuples are defined by a comma-separated list of items in parentheses.

Features: 1, ordered set, 2, through the offset to fetch data, 3, belong to the immutable object, can not be modified in situ content, no sorting.

P.S. The immutable benefits of the tuple: ensuring data security, such as passing data to an unfamiliar method or interface, guarantees that the method or interface does not alter our data, which can lead to procedural problems.

0X01 Basic Operations

>>> A = (all in a)    # definition >>> a[0]1>>> A[1:3]    # slices (2,3)

>>> B = (,) #当元组中只包含一个元素时, you need to add a comma after the element to disambiguate

The purpose of modifying tuples can be achieved by overriding the values

>>> a = (a) >>> B = List (a)    # changes a non-modifiable tuple to a list that can be modified >>> b[0] = 4 >>> a = tuple (b)>>> A (4,2,3)

Python Basics: 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.