Python 0 Basic Primer (8)-------tuple tuples

Source: Internet
Author: User

An immutable sequence of tuple tuples. Contains arbitrary objects. can be nested arbitrarily. Accessed through the following table. No support for in-situ changes

Immutable refers to not supporting in-situ changes, nor appending elements and extension elements like lists

Syntax: t = () parentheses represent tuples

Problem:

If we write T = (' Mike ') directly. This will be treated as a string, and you want to declare that the tuple needs to write T = ("Mike")

When assigning tuples, parentheses can be omitted.

The tuple () function converts an iterative sequence into a tuple

Access to tuples is consistent with list access

Some other actions: (The following operation produces a new object)

The common operation of tuples is consistent with the general operation of the list, such as:

T in Tuple1 an element inside a tuple

T in Tuple1 an element is not inside a tuple

Tuple1 + tuple2

Tuple1 * 2

Tuple[index]

tuple[I:j]

tuple[i:j: K]

Len (tuple) tuple length

MIN (tuple) Minimum value

Max (tuple) maximum value

SUM (tuple) Total

Tuple.index (x) The first occurrence of an element in a tuple subscript

Tuple.count (x) an element appears several times

Extended:

A, B = 5, 10 This is the assignment of 2 variables respectively. Instead of declaring a tuple

The value of the interchange A and B can be so sub-written A, B = B, a

Python 0 Basic Primer (8)-------tuple tuples

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.