Python basic data type--tuple

Source: Internet
Author: User

One, the creation and transformation of tuples:
Ages = (one, 22, 33, 44, 55) Ages = Tuple (11
ages = tuple ([]) # string, list, dictionary (default is key)
    • Tuples can basically be viewed as non-modifiable lists
    • Tuple (iterable), which can hold all data types that can be iterated
The immutability of the tuple

such as: T = (+, ' Jesse ', (' Linuxkernel ', ' Python '), [+, ' Jesse '])
The element number 17 in the tuple T and the string ' Jesse ' as well as the tuple (' Linuxkernel ', ' Python ') itself are immutable elements, so it is not updatable in tuples, but the list contained therein [N, ' Jesse '] itself belongs to a mutable element, so:

>>> T = (+, ' Jesse ', (' Linuxkernel ', ' Python '), [+, ' Jesse ']) >>> t (+, ' Jesse ', (' Linuxkernel ', ' Pytho n '), [+, ' Jesse ']) >>> t[0] = 18Traceback (most recent call last):  File "<stdin>", line 1, in <modul E>typeerror: ' Tuple ' object does not support item assignment>>> t[3][17, ' Jesse ']>>> t[3][0] = 21> >> T (+, ' Jesse ', (' Linuxkernel ', ' Python '), [+, ' Jesse '])
Three, meta-group common operations
#count (self,value) #功能: Counts the number of elements in the current tuple Tup = (55,77,85,55,96,99,22,55,) Tup.count #返回结果: 3   element ' 55 ' appears 3 times in tuple Tup # Index (self, value, Start=none, stop=none) function: Gets the index value of the element in the tuple, and for the repeating element, the default gets the index value of the first element from the Left Tup = (55,77,85,55,96,99,22,55,) Tup.index (55) Results returned: 0tup.index (85) return Result: 2tup.index (55,2,7) return result: 3
Tuple source Code

Python basic data type--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.