Home  >  Article  >  Backend Development  >  How to add elements to the end of a list in python

How to add elements to the end of a list in python

王林
王林Original
2020-08-25 14:23:458261browse

Python method to add elements at the end of the list: You can use the append() method to add. The append() method is used to add new objects to the end of the list, for example: [list1.append(list2)].

How to add elements to the end of a list in python

Method introduction:

(Recommended tutorial: python tutorial)

append() method Used to add new objects at the end of the list.

Note: This method has no return value, but will modify the original list.

Grammar:

list.append(obj)

Implementation code:

#声明两个列表 list1和list2
list1=['H','E','L','L','O']
list2=['1','2','3','4']
#append()
list1.append(list2)
#打印现在的list1
print(list1)

Running result:

How to add elements to the end of a list in python

The above is the detailed content of How to add elements to the end of a list in python. 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