如何在python中获取任意大小的空数组? [英] How do I get an empty array of any size in python?

查看:18
本文介绍了如何在python中获取任意大小的空数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基本上想要一个在 C 中的 Python 等价物:

I basically want a python equivalent of this in C:

int a[x];

但在python中我声明了一个数组,如:

but in python I declare an array like:

a = []

问题是我想用以下值分配随机插槽:

and the problem is I want to assign random slots with values like:

a[4] = 1

但我不能用 python 来做,因为数组是空的.

but I can't do that with python, since the array is empty.

推荐答案

如果数组"实际上是指 Python 列表,则可以使用

If by "array" you actually mean a Python list, you can use

a = [0] * 10

a = [None] * 10

这篇关于如何在python中获取任意大小的空数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆