Python list (Day 1)

Source: Internet
Author: User
Tags python list

name=['Liutao','Chuyunfei','Qifei','Xianmoumou']#Define a list#AddName.append ('123')#appends an element at the end of the list with only one additionalName.insert (1,'Liutao2')#you can add elements anywhere in the list, but the previous one is the index value, the index starts at 0, followed by the added content, and cannot be inserted in bulk#Modifyname[2]='Chenyifa'                           #to modify an element in a list by index subscript#DeleteName.remove ('Chenyifa')delName[2]name.pop ()#deletes the last element of the list by default, and also adds an index value#FindPrint(Name.index ('Liutao'))#Find element Index value#Extendedname2=['Liufeier',' the','Xianmoumou']#to expand a list by listName.extend (name2)#This must be done first extend, directly change the contents of the list itself, directly with print (Name.extend (name2)) will be displayed as nonePrint(name)#to calculate duplicate elements in a listPrint(Name.count ('Xianmoumou'))#Clear Listname.clear ()#Reverse ListName.reverse ()#and extend .#SortName.sort ()#sort order for special characters > Numbers > Uppercase letters > Lowercase letters ASCII sortPrint(name)#Print the entire listPrint(Name[0])#print an element with an index of 0 in the listPrint(Name[1:4])#Print the elements of the list index number 1 to 4

Note:

The reverse function, for the operation of the list, the result is to directly change the list itself (in order to save space), so the original list is changed directly to the result of the reversed you want, and the return value, is empty, does not return any value. Some other functions do the same

Python list (Day 1)

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.