Home > Article > Backend Development > How to add elements to the end of a list in python
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)].
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:
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!