Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
291 views
in Technique[技术] by (71.8m points)

python - 如何在Python中声明一个数组?(How to declare an array in Python?)

How do I declare an array in Python ?

(如何在Python中声明数组?)

I can't find any reference to arrays in the documentation.

(我在文档中找不到任何对数组的引用。)

  ask by translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
variable = []

Now variable refers to an empty list * .

(现在variable引用空列表* 。)

Of course this is an assignment, not a declaration.

(当然这是一项任务,而非宣言。)

There's no way to say in Python "this variable should never refer to anything other than a list", since Python is dynamically typed.

(在Python中没有办法说“这个变量永远不应该引用除列表之外的任何东西”,因为Python是动态类型的。)


* The default built-in Python type is called a list , not an array.

(*默认的内置Python类型称为列表 ,而不是数组。)

It is an ordered container of arbitrary length that can hold a heterogenous collection of objects (their types do not matter and can be freely mixed).

(它是一个任意长度的有序容器,可以容纳异质的对象集合(它们的类型无关紧要,可以自由混合)。)

This should not be confused with the array module , which offers a type closer to the C array type;

(这不应该与array模块混淆, array模块提供更接近C array类型的类型;)

the contents must be homogenous (all of the same type), but the length is still dynamic.

(内容必须是同质的(所有相同的类型),但长度仍然是动态的。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...