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

查看:431
本文介绍了如何在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天全站免登陆