Python list function description

Source: Internet
Author: User
Tags python list

1 #Create a list2list1=['Python', 5,0.2]3list2=['I',' Love']4 5 #access elements by subscript6 Print(list1[0])7 Print(list1[1])8 Print(list2[-1])9 Ten Print(List1[0:2]) One Print(List1[:2]) A Print(list2[:]) - Print(list2[0:]) -  the #add element to end of list -List1.append (3.1) - Print(List1) - #inserting elements at I +List2.insert (1,'really') - Print(LIST2) + #deletes the first specified element of the list AList1.remove (3.1) at Print(List1) - #returns the first specified element of the list - Print(List1.index (0.2, )) - #returns the number of occurrences of an element in a list - Print(List1.count (0.2)) - #Add a list to the end of a list in list2.extend (List1) - Print(LIST2) to #Reverse List + List2.reverse () - Print(LIST2) the #list Element Sort *list3=[2,3,1,6,0,9,8,] $ List3.sort ()Panax Notoginseng Print(LIST3) - #Delete the specified element and return it, parameter optional, delete last element without argument theL3=list3.pop (3) + Print(L3) A Print(LIST3)

Python list function description

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.