NameError:名称“数组”未在python中定义 [英] NameError: name 'array' is not defined in python

查看:222
本文介绍了NameError:名称“数组”未在python中定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我要创建数组时,我得到 NameError:未定义名称'array'在python错误中,例如:

I get NameError: name 'array' is not defined in python error when I want to create array, for example:

a = array([1,8,3])

我在做什么错?

推荐答案

如果需要一个容器来存放一堆东西,那么列表可能是最好的选择:

If you need a container to hold a bunch of things, then lists might be your best bet:

a = [1,8,3]

类型

dir([])

从Python解释器查看列出支持的方法,例如append,pop,reverse和sort。
列表还支持列表解析和Python的可迭代界面:

from a Python interpreter to see the methods that lists support, such as append, pop, reverse, and sort. Lists also support list comprehensions and Python's iterable interface:

for x in a:
    print x

y = [x ** 2 for x in a]

这篇关于NameError:名称“数组”未在python中定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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