Home >Web Front-end >JS Tutorial >Python implements addition, deletion and modification of array list

Python implements addition, deletion and modification of array list

php中世界最好的语言
php中世界最好的语言Original
2018-04-09 17:12:031774browse

This time I will bring you pythonimplementation of adding, deleting, and modifying arrayslist. What are the notesof implementing additions, deletions, and modifications of arrays in python? The following is the actual combat. Let’s take a look at the case.

An array is an ordered collection that can be added and deleteelements at any time

book = ['xiao zhu pei qi','xiao ji qiu qiu','tang shi san bai shou']// 定义book数组

1. Add .insert/.append

book.insert(0,'bu yi yang de ka mei la')//.insert(x,'xx') 在指定位置添加,x/第几位 , 'xx'/添加的内容
book.append('e ma ma tong yao') //.append('') 在末尾添加

2. Modify the element

book[2]='pei qi going swimming' //修改第二个位置为'pei qi going swimming'

3. Delete .pop()

book.pop() //删除末尾
book.pop(X) //删除指定位置的内容,x=0-x

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

python operation matrix rows

How to perform automated unit testing with Python Unittest

The above is the detailed content of Python implements addition, deletion and modification of array list. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn