0 Basic python-9.1 tuples

Source: Internet
Author: User

Tuples: Composed of simple groups of objects

Characteristics:

1. An ordered set of arbitrary objects

2. Access by offset

3. Immutable sequence Type

4. Fixed-length, heterogeneous, arbitrary nesting

5. Array of object references

Operation Explain
() Empty tuple
t= (0,) Tuple of a single element
T=0, ' a ', 1.2,3 4 Elements of a tuple
t= (' A ', (' A ', ' B ')) Nested tuples
T=tuple (' a ') Can iterate over objects
T[i] Index
T[I][J] Index of Index
T[I:J] Sharding
Len (t) Length
T1+t2 Merge
T*3 Repeat
For x in T:print (x) Iteration
' A ' in t Member relationships
[x**2 for x in T] Iteration
T.index (' a ') Search
T.count (' a ') Count

2. Basic operation

The operations of merging, repeating, nesting, sharding, and indexing are reflected in the following code


3. Sorting


By converting tuples into lists, and then calling list methods to sort operations

Generating tuples with list parsing


Why is there a list and a tuple?

Because the tuple's non-modifiable, because the tuple is not modifiable, he as a parameter when passed, do not always pay attention to the consistency of data

Right here, thank you.

------------------------------------------------------------------

Click to jump 0 basic python-Catalogue

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

0 Basic python-9.1 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.