Python add and delete list elements

Python has a built-in method append() for adding elements to the list. This method can directly add elements to the end of the list.

First create an empty list, and then use append() to add 3 elements.

 

The append() method is to insert an element at the end of the list, and the insert() method is to insert an element at any position. Its usage format is as follows:

 

The biggest advantage of using the pop() method to delete an element is that the deleted value will pop up after deletion. If you do not specify the position of the deleted element when using pop(),

Always delete elements at the end of the list. The usage of pop() is as follows:

 

in

Guess you like

Origin blog.csdn.net/m0_55389447/article/details/114961368