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

王林
Release: 2020-08-25 14:23:45
Original
8206 people have browsed it

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)
Copy after login

Implementation code:

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

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!

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!