How to declare an array in Python

0 votes
How do I declare an array in Python?

I can't find any reference to arrays in the documentation.
Jan 5 in Python by Rajiv
• 8,880 points
463 views

1 answer to this question.

0 votes
variable = []

Now variable refers to an empty list*.

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.


*The default built-in Python type is called a list, not an array. It is an ordered container of arbitrary length that can hold a heterogeneous 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; the contents must be homogenous (all of the same type), but the length is still dynamic

answered Jan 5 by Gitika
• 65,870 points

Related Questions In Python

+4 votes
7 answers
0 votes
1 answer
0 votes
1 answer
+1 vote
12 answers
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 2,047 views
0 votes
0 answers
0 votes
1 answer

I want to download a file from the website by web scraping. Can anyone explain how to do this in jupyter lab (python) with an example?

Hey, Web scraping is a technique to automatically ...READ MORE

answered Apr 7, 2020 in Python by Gitika
• 65,870 points
669 views
0 votes
1 answer

How to insert an object at a given index in Python?

Hi, @Roshni, I will explain to you with ...READ MORE

answered Jun 23, 2020 in Python by Gitika
• 65,870 points
144 views