I follow the book, summarize the implementation to record, do not feel simple to try, knock a code. Executive power is the sword of a good programmer. If you are a novice in mastering other language situations such as Java, C or PHP and so on any kind of basic grammar, the program is all the same, you can follow my record and I will step-by-step learning python.The Scarlet Letter is to pay attention to the place, during python2 and Python3 differences need to note that I will also be Red character logo.
1. Array index
# This is the number of square brackets [], the same as the index starting from 0, 1 means the last start-2 is the penultimate array_full=['aaa',' BBB','CCC'print(array_full[0]) Print (array_full[-1]) # Output AAACCC
2. Modify, insert, delete elements
array_full=['AAA','BBB','CCC'] #Modifyarray_full[0]="DDD < can specify the location > Print(array_full)#Output['DDD','BBB','CCC'] #add append ()Array_full.append ('DDD')Print(array_full)#Output['AAA','BBB','CCC','DDD'] #inserting insert ()Array_full.insert (0,'DDD') < can specify location > Print(array_full)#Output['DDD','AAA','BBB','CCC'] #Delete deldelArray_full[0] < can specify location > Print(array_full)#Output['BBB','CCC'] #Delete and eject the deleted element, the default last value can also specify a location. Pop ()Pop_this=array_full.pop (1) < can specify location > Print(pop_this)Print(array_full)#Outputbbb['AAA','CCC']
#根据值删除 remove (), note: If the same value appears multiple times in the list, you need to iterate to delete the specified value Array_ Full.remove ( ' bbb) print (Array_full) Span style= "color: #008000;" ># output [ ' aaa " ccc '
Python record-Getting started to practice-array Operations Chapter 1 (ii)