Python list method

Source: Internet
Author: User

#-*-coding:utf-8-*-names= ["AA","BB","cc","DD",]" "Enquiry" "#slicesPrint(Names[1:3])#take the last elementPrint(names[-1])#take all elements after the second elementPrint(names[2:])" "Add" "#append a single elementNames.append ("ee")Print(names)#Insert an elementNames.insert (2,"FF")Print(names)" "Delete" "#Delete by valueNames.remove ("DD")Print("Delete", names)#Delete by subscriptdelNames[0]Print("Delete index:", names)#Delete the last element, or you can specify the subscript to delete the specified subscript elementNames.pop ()Print("Delete Pop", names)" "Modify" "names[2] ="GG"Print(names)#Get IndexPrint(Names.index ("BB")) Names.append ("ee") Names.append ("ee")#gets the number of an element in the listPrint("number of EE:", Names.count ("ee"))#Reverse ListNames.reverse ()Print(names)#SortNames.sort ()Print(names)#Merging a listName2 = [A]names.extend (name2)Print(names)#Delete name2 this listdelname2Print(name2)

Python list method

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.