Python----data type----list

Source: Internet
Author: User
Tags shallow copy

1 #list:2name = ["LC","PXM","PT"]3 Print('------------', Name[2],"----------")4 5 #list slices6 Print(Name[1:3])#slices7 Print(Name[:3])8 Print(Name[-1])#take the last one .9 Print(name[-2:])#take the last two digitsTen  One #List Additions AName.append ("Huanglei")#finally add an object -Name.insert (1,"xulingling")#inserts an object at the specified location -  the #List Delete -Name.remove ("Lvcheng")#Delete directly, delete the specified object - delName[1] -Name.pop (1)#Delete the last object by default, specify a location to delete +  - #List Modification +name[1]="smq" A Print(name) at  - #List Operations -Name.index ("smq")#find where objects correspond -Name.count ("Lvcheng")#number of occurrences of an object in the statistics list -Name.reverse ()#List Reversal -Name.sort ()#list sort, by ASCII inName2 = [A] -Name.extend (name2)#list extension, extending another list to the list toName.clear ()#Clear List + delName2#Delete List -  the #list replication: *name = ["LC","PXM",["Alex","Jack"],"PT"] $name2 = Name.copy ()#List copy, copy as shallow copy, does not copy list within listPanax Notoginseng Print(name) - Print(name2) thename[2][0]="ALEXANDER" + Print(name) A Print(name2)

1 #List Deep Copy2 ImportCopy3name = ["LC","PXM",["Alex","Jack"],"PT"]4Name2 =copy.deepcopy (name)5 Print(name)6 Print(name2)7name[2][0]="ALEXANDER"8 Print(name)9 Print(name2)
code Execution Results ['LC','PXM', ['Alex','Jack'],'PT']['LC','PXM', ['Alex','Jack'],'PT']['LC','PXM', ['ALEXANDER','Jack'],'PT']['LC','PXM', ['Alex','Jack'],'PT']
1name = ["LC","PXM",["Alex","Jack"],"PT","GGG","Dex","Fed","FCK"]2 #Step slices3 Print(Name[0:-1:2])#indicates how much from the beginning of the printed list to how many ends, and the last represents the interval4 Print(Name[::2])5 #List Loops6  forIinchName:7     Print(i)

Python----data type----list

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.