Home > Web Front-end > JS Tutorial > body text

Python implements addition, deletion and modification of array list

php中世界最好的语言
Release: 2018-04-09 17:12:03
Original
1739 people have browsed it

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数组
Copy after login

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('') 在末尾添加
Copy after login

2. Modify the element

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

3. Delete .pop()

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!