python创建 array
时间: 2023-06-18 15:03:05 浏览: 78
在 Python 中,我们可以使用 `array` 模块来创建数组。下面是一个简单的例子:
```python
import array as arr
# 创建一个整数类型的数组
a = arr.array('i', [1, 2, 3, 4, 5])
# 输出数组中的元素
for i in a:
print(i)
```
在上面的代码中,我们首先导入了 `array` 模块,并使用 `array` 函数来创建一个整数类型的数组 `a`,其中的 `'i'` 表示整数类型。然后我们使用 `for` 循环来遍历数组中的元素,并将它们逐个输出。
阅读全文
相关推荐









