Python Basics 2

Source: Internet
Author: User

Reference Address: https://www.cnblogs.com/alex3714/articles/5717620.html

    • list, tuple operations

List

>>> List1 = ['Physics','Chemistry', 1997, 2000];#access List>>>List1[0]'Physics'>>> List1[0:2]['Physics','Chemistry']>>> List1[-1]#adding a symbol is to access the element from the back forward2000#Update list>>> list1[2] ="ABCD">>>list1['Physics','Chemistry','ABCD', 2000]#Delete List>>>delList1[2]>>>list1['Physics','Chemistry', 2000]#Add new at the end of the list>>> List1.append ("newobj")>>>list1['Physics','Chemistry', 1997, 2000,'newobj']#Count the number of occurrences of an element in a list>>> List1.count (1997)1#inserting an object into a list>>> List1.insert (2,"Insertobj")>>>list1['Physics','Chemistry','Insertobj', 1997, 2000,'newobj']#removes an element from the list (the last element by default), and returns the value of the element>>> result=List1.pop ()>>>result'newobj'>>>list1['Physics','Chemistry','Insertobj', 1997, 2000]#to remove the first occurrence of a value in a list>>> List1.remove (1997)>>>list1['Physics','Chemistry','Insertobj', 2000]#append multiple values from another sequence at the end of a list>>> List1.extend ([1,2,3,4])>>>list1['Physics','Chemistry','Insertobj', 2000, 1, 2, 3, 4]#reverse List of elements>>>List1.reverse ()>>>list1[4, 3, 2, 1, 2000,'Insertobj','Chemistry','Physics']#sort the original list to sort only on the same data type>>> List1 = ['Physics','Chemistry','Insertobj']>>>List1.sort ()>>>list1['Chemistry','Insertobj','Physics']

Meta-group

Tuples are also called read-only lists

  

  

Python Basics 2

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.