How to add data to an empty array in Python.
In Python, we can use lists to define an empty array and add data to the array using the append() method.
Here is an example code:
# 定义一个空数组
arr = []
# 添加数据到数组中
arr.append(1)
arr.append(2)
arr.append(3)
print(arr) # 输出: [1, 2, 3]
In the above code, we start by creating an empty array called ‘arr’ and then use the append() method to add data to the array. Each time the append() method is called, it adds an element to the end of the array. Finally, we use the print() function to display the contents of the array.