Instructions for Python tuple tuples

Source: Internet
Author: User

The characteristic of a tuple is that its elements are immutable (immutable), and once set, it cannot be modified using an index.

>>> t1=1,2,3,4,5 #给Tuple赋值 >>> t1[0] #按照索引读取Tuple元素1 > >> u1=t1, (2,3,4,5,6) #tuple可以嵌套 >>> U1 ((1, 2, 3, 4, 5), (2, 3, 4, 5, 6)) >>> U1[1] (2, 3, 4, 5, 6) > >> U1[-1] (2, 3, 4, 5, 6) >>> u1=t1, (2,3,4,5,6),3>>> U1 ((1, 2, 3, 4, 5), (2, 3, 4, 5, 6), 3) >> > list1=[' we ', ' the ', ' North ']>>> list1[' we ', ' the ', ' North ']>>> u1=t1,list1>>> U1 ((1, 2, 3, 4, 5), [' we ', ' the ', ' North '] >>> list1[-1]= ' Toronto ' #元组内的元素是可变的, so you can modify the inner element to update tuples >>> U1 ((1, 2, 3, 4, 5), [' we ', ' the ', ' Toronto ']) >>> len (u1) 2>>> myList = [1,2,3,4,5,6,7,8,9,10]>>> Mytuple = ( 1,2,3,4,5,6,7,8,9,10) >>> mylist= (2,) #初始化一个元素的时候, need to take comma>>> myList (2,) >>> mylist[0]2  >>> Mylist[1]traceback (most recent): File ' <stdin> ', line 1, in <module>indexerror:tuple Index out of range>>> len (myList) 1 

Instructions for Python 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.