Python record-Getting started to practice-array Operations Chapter 1 (ii)

Source: Internet
Author: User

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)

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.