If you are doing statistics for a region, you can use lists to help us. Type in Chinese characters or other characters like "01 for Han", then when you write ethnicity with a drop down list, you can type 01 and it will be automatically recognized as Han. Lists are used for large-scale data filling, in python, there is also a lot of use to the list, then you know how to add a new object at the end of the list? Today, we will recognize the append function in python that can add elements at the end of the list.
1. append() function
Used to add a new object to the end of the list.
2. Grammar
(obj)
3. Parameters
list: list object;
obj:Object to add to the end of the list.
4、Return Value
The append() function has no return value, but modifies the original list.
5. Examples of use
#!/usr/bin/python #Filename: a=[-1,3,'aa',85,90,'dasd'] ('add') print a
exports
[-1, 3, 'aa', 85, 90, 'dasd', 'add']
Knowledge Point Expansion:
Generate multidimensional arrays with append:
import numpy as np a=[] for i in range(5): ([]) for j in range(5): a[i].append(i)
The results are as follows:
[[0, 0, 0, 0, 0], [1, 1, 1, 1, 1], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [4, 4, 4, 4, 4]]
to this article on the use of python append function explains the article is introduced to this, more related to how to use python append function content, please search for my previous articles or continue to browse the following related articles I hope you will support me in the future more!