In the first one you add the arrays of length 10 to the bigger array. So you need to create two arrays.

array1 = []
array2 = []
for j in range(20):
    for i in range(10):
        array1.append(0)
    array2.append(array1)
    array1 = []
print array2

This is equivalent to

array2=[[0 for j in range(10)] for i in range(20)]
Answer from Rolf Lussi on Stack Overflow
๐ŸŒ
Quora
quora.com โ€บ How-do-I-create-an-array-for-loop-in-Python
How to create an array for loop in Python - Quora
Answer (1 of 3): If names is an array, you can loop to process it as such: for name in names: # do something # some other thing If you want to filter one list to create new list, use list comprehension. new names = [val for val in names if val != โ€˜ 'โ€™] This will create a new list...
๐ŸŒ
PyTutorial
pytutorial.com โ€บ make-an-array-in-python
PyTutorial | How to Create Array in Python Using For loop
March 5, 2020 - # Define an empty list my_array = [] # Use a for loop to iterate and append elements to the array for i in range(5): my_array.append(i) # Print the array print(my_array)
Discussions

Trying to create multiple arrays with different names using a for loop
You don't want to manually write unique names for each array like this, you'll then have to manually write each of their unique names when you want to use them again. In this case, you have an unknown number of arrays, so don't even know how many you have to write. Rather you make a list, which itself contains multiple lists. my_array = [] #create empty list for i in range(Number_Of_items): content = ['a', 'b', 'c'] #we generate our content as a list my_array.append(content) #then add our content to my_array at position i """ my_array = [['a', 'b', 'c'], ['a', 'b', 'c'], ['a', 'b', 'c']] """ #to retrieve specific element print(my_array[2][0]) #3rd list, element 0 -> 'a' BTW, in python it's usually referred to as lists rather than array. More on reddit.com
๐ŸŒ r/learnpython
5
1
April 8, 2023
Creating arrays with for and while loops - Python 2 - Stack Overflow
How can I tweak these loops in order to create the same effect as the first one? Thank you. ... In the first one you add the arrays of length 10 to the bigger array. More on stackoverflow.com
๐ŸŒ stackoverflow.com
March 10, 2016
Creating new array in for loop (Python) - Stack Overflow
I'm preparing a data set to run in the program rpy (R, which runs in Python) for statistical analysis. It looks like this: data = [[0, 1, 0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 1, 0, 0, 1, 0, 0, 0, 0], ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
January 15, 2013
Assign values to array during loop - Python - Stack Overflow
I am currently learning Python (I have a strong background in Matlab). I would like to write a loop in Python, where the size of the array increases with every iteration (i.e., I can assign a newly More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 54948120 โ€บ how-to-make-an-array-within-a-for-loop
python - How to make an array within a for loop? - Stack Overflow
for i in range(len(DH4_3)): Keqs=np.exp(-(DH4_3[i]-T4[i+127]*DS4)/(R*T4[i+127])) print(Keqs) I want to assign the index [i] to each Keqs[i] The goal is to be able to indexing Keq, for ins...
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ gloss_python_array_loop.asp
Python Loop Through an Array
Python Examples Python Compiler ... Bootcamp Python Certificate Python Training ... You can use the for in loop to loop through all the elements of an array....
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ trying to create multiple arrays with different names using a for loop
r/learnpython on Reddit: Trying to create multiple arrays with different names using a for loop
April 8, 2023 -

Hi looking for help with a current project Iโ€™m doing. I have a variable Number_Of_items which is an integer number read from a .txt file. Im trying to create a number of arrays equivalent to the variable Number_Of_items . For example if the value for Number_Of_items was 6, I would want to create 6 arrays with names array1, array2 , array3 etc. if anyone could point me in the right direction it would be appreciated.

Find elsewhere
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_arrays.asp
Python Arrays
Note: This page shows you how to use LISTS as ARRAYS, however, to work with arrays in Python you will have to import a library, like the NumPy library. Arrays are used to store multiple values in one single variable: ... An array is a special variable, which can hold more than one value at a time. If you have a list of items (a list of car names, for example), storing the cars in single variables could look like this: ... However, what if you want to loop through the cars and find a specific one?
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ python_loop_arrays.htm
Python - Loop Arrays
import array as arr # creating ... of array with built-in len() function. Use it to create a range object to get the series of indices and then access the array elements in a for loop....
๐ŸŒ
AskPython
askpython.com โ€บ home โ€บ 3 ways to initialize a python array
3 ways to initialize a Python Array - AskPython
January 16, 2024 - Now, let us look at the different ways to initialize an array in Python. Python for loop and range() function together can be used to initialize an array with a default value.
๐ŸŒ
GitHub
hplgit.github.io โ€บ bumpy โ€บ doc โ€บ pub โ€บ sphinx-basics โ€บ ._basics001.html
Variables, loops, lists, and arrays
Let the \(t\) values go from 0 to 2 in increments of 0.1. The following program applies a while loop: v0 = 2 a = 0.2 dt = 0.1 # Increment t = 0 # Start value while t <= 2: s = v0*t + 0.5*a*t**2 print t, s t = t + dt ยท The result of running this program in a terminal window is ยท Terminal> python while.py 0 0.0 0.1 0.201 0.2 0.404 0.3 0.609 0.4 0.816 0.5 1.025 0.6 1.236 0.7 1.449 0.8 1.664 0.9 1.881 1.0 2.1 1.1 2.321 1.2 2.544 1.3 2.769 1.4 2.996 1.5 3.225 1.6 3.456 1.7 3.689 1.8 3.924 1.9 4.161
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ how to create array of strings in python
How to Create Array of Strings in Python - Spark By {Examples}
December 20, 2024 - # Iterate array of stings using for loop # get the strings for str in arr_str: print(str) # Output: # Spark # by # examples ยท Alternatively, you can use a while loop to access each string present in the array. Using a while loop you can iterate a string as long as the condition is True.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 41308976 โ€บ is-it-possible-to-create-array-of-variables-in-a-python-for-loop
Is it possible to create array of variables in a python for loop? - Stack Overflow
If you want all words in a list at the end you can use list variable declared at the start. If you want all the lengths stored in a list, change lengths = 0 for lengths = [] and append each length in the for loop (lengths.append(len(list[e]))
๐ŸŒ
The Knowledge Academy
theknowledgeacademy.com โ€บ blog โ€บ python-array
Python Arrays: Everything You Should Know
November 21, 2025 - The โ€œarrayโ€ module in Python provides a straightforward approach to creating Arrays. To use this module, you first need to import it into your code. Then, you can declare an Array by specifying the type of elements it will contain.
๐ŸŒ
Hostman
hostman.com โ€บ tutorials โ€บ how to create an array in python
How to create an array in Python: A Step-by-Step Guide | Hostman
December 23, 2025 - So, the array function makes arrays available in a Python program. While it can be called using different methods, this one seems the most convenient, as it minimizes the number of subsequent errors: ... Of course, this command, like other general instructions, must be indicated in the "header" of the code, that is, at the very top. ... array_name is the name (you can set any name that adheres to the rules for creating variables in Python);
Price ย  $
Call ย  +1 844 286 2130
Address ย  1999 Harrison St 1800 9079, 94612, Oakland
Top answer
1 of 16
427
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 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; the contents must be homogenous (all of the same type), but the length is still dynamic.

2 of 16
196

This is surprisingly complex topic in Python.

Practical answer

Arrays are represented by class list (see reference and do not mix them with generators).

Check out usage examples:

# empty array
arr = [] 

# init with values (can contain mixed types)
arr = [1, "eels"]

# get item by index (can be negative to access end of array)
arr = [1, 2, 3, 4, 5, 6]
arr[0]  # 1
arr[-1] # 6

# get length
length = len(arr)

# supports append and insert
arr.append(8)
arr.insert(6, 7)

Theoretical answer

Under the hood Python's list is a wrapper for a real array which contains references to items. Also, underlying array is created with some extra space.

Consequences of this are:

  • random access is really cheap (arr[6653] is same to arr[0])
  • append operation is 'for free' while some extra space
  • insert operation is expensive

Check this awesome table of operations complexity.

Also, please see this picture, where I've tried to show most important differences between array, array of references and linked list:

๐ŸŒ
Dataquest
dataquest.io โ€บ blog โ€บ tutorial-advanced-for-loops-python-pandas
Tutorial: Advanced Python for Loops โ€“ Dataquest
March 11, 2025 - Now, let's take a look at how for loops can be used with common Python data science packages and their data types. We'll start by looking at how to use for loops with numpy arrays, so let's start by creating some arrays of random numbers.
๐ŸŒ
Studytonight
studytonight.com โ€บ python-howtos โ€บ how-to-declare-an-array-in-python
How to declare an array in Python - Studytonight
As mentioned earlier, there is ... "bat", "rat"] Here, we declare an empty array. Python for loop and range() function is used to initialize an array with default values....