First of all, this is not an array. This is a list. Python does have built-in arrays, but they are rarely used (google the array module, if you're interested). The structure you see is called list comprehension. This is the fastest way to do vectorized stuff in pure Python. Let's get through some examples.

Simple list comprehensions are written this way: [item for item in iterable] - this will build a list containing all items of an iterable.

Actually, you can do something with each item using an expression or a function: [item**2 for item in iterable] - this will square each element, or [f(item) for item in iterable] - f is a function.

You can even add if and else statements like this [number for number in xrange(10) if not number % 2] - this will create a list of even numbers; ['even' if not number % 2 else 'odd' for number in range(10)] - this is how you use else statements.

You can nest list comprehensions [[character for character in word] for word in words] - this will create a list of lists. List comprehensions are similar to generator expressions, so you should google Python docs for additional information.

List comprehensions and generator expressions are among the most powerful and valuable Python features. Just start an interactive session and play for a while.

P.S.

There are other types of comprehensions that create sets and dictionaries. They use the same concept. Google them for additional information.

๐ŸŒ
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....
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ for-loops-in-python
For Loops in Python
February 1, 2020 - For Loop Statements Python utilizes a for loop to iterate over a list of elements. Unlike C or Java, which use the for loop to change a value in steps and access something such as an array using that value.
Discussions

list comprehension - python array creation syntax [for in range] - Stack Overflow
I came across the following syntax to create a python array. It is strange to me. Can anyone explain it to me? And how should I learn this kind of syntax? [str(index) for index in range(100)] More on stackoverflow.com
๐ŸŒ stackoverflow.com
Python arrays
If you're just learning, just use lists. They have essentially the same interface (meaning everything you can do to an array, you can do to a list), and while they are somewhat less performant, if you're just poking around, that's probably not important. If the performance is a consideration, use NumPy. If you want really fine control over exactly how memory is laid out, use a different language. More on reddit.com
๐ŸŒ r/learnpython
13
3
March 3, 2025
python - What does [:] mean? - Stack Overflow
I'm analyzing some Python code and I don't know what pop = population[:] means. Is it something like array lists in Java or like a bi-dimensional array? More on stackoverflow.com
๐ŸŒ stackoverflow.com
Need help for Python 2D array groupby
Those aren't errors as far as I can tell. Those are just describing the objects. What is your code? More on reddit.com
๐ŸŒ r/learnpython
4
1
January 8, 2021
People also ask

What is the difference between array.array and NumPy arrays?
array.array is a built-in Python module suitable for basic numeric arrays, while NumPy arrays offer advanced mathematical operations, faster performance, and support for multi-dimensional data.
๐ŸŒ
mygreatlearning.com
mygreatlearning.com โ€บ blog โ€บ it/software development โ€บ python array & how to use them [with examples]
Python Array & How To Use Them [With Examples]
Can I slice arrays like lists in Python?
Yes, both array.array and lists support slicing. For example: arr[1:3] # Returns a slice from index 1 to 2
๐ŸŒ
mygreatlearning.com
mygreatlearning.com โ€บ blog โ€บ it/software development โ€บ python array & how to use them [with examples]
Python Array & How To Use Them [With Examples]
Is it possible to sort an array created with array.array?
Yes, you can use the built-in sorted() function or convert the array to a list, sort it, and convert it back.
๐ŸŒ
mygreatlearning.com
mygreatlearning.com โ€บ blog โ€บ it/software development โ€บ python array & how to use them [with examples]
Python Array & How To Use Them [With Examples]
๐ŸŒ
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...
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ numpy โ€บ numpy_array_iterating.asp
NumPy Array Iterating
As we deal with multi-dimensional arrays in numpy, we can do this using basic for loop of python.
Top answer
1 of 3
10

First of all, this is not an array. This is a list. Python does have built-in arrays, but they are rarely used (google the array module, if you're interested). The structure you see is called list comprehension. This is the fastest way to do vectorized stuff in pure Python. Let's get through some examples.

Simple list comprehensions are written this way: [item for item in iterable] - this will build a list containing all items of an iterable.

Actually, you can do something with each item using an expression or a function: [item**2 for item in iterable] - this will square each element, or [f(item) for item in iterable] - f is a function.

You can even add if and else statements like this [number for number in xrange(10) if not number % 2] - this will create a list of even numbers; ['even' if not number % 2 else 'odd' for number in range(10)] - this is how you use else statements.

You can nest list comprehensions [[character for character in word] for word in words] - this will create a list of lists. List comprehensions are similar to generator expressions, so you should google Python docs for additional information.

List comprehensions and generator expressions are among the most powerful and valuable Python features. Just start an interactive session and play for a while.

P.S.

There are other types of comprehensions that create sets and dictionaries. They use the same concept. Google them for additional information.

2 of 3
4

List comprehension itself is concept derived from mathematics' set comprehension, where to get new set, you specify parent set and the rule to filter out its elements.

In its simplest but full form list comprehension looks like this:

[f(i) for i in range(1000) if i % 2 == 0]

range(1000) - set of values you iterates through. It could be any iterable (list, tuple etc). range is just a function, which returns list of consecutive numbers, e.g. range(4) -> [0, 1, 2, 3]

i - variable will be assigned on each iteration.

if i%2 == 0 - rule condition to filter values. If condition is not True, resulting list will not contain this element.

f(i) - any python code or function on i, result of which will be in resulting list.

For understand concept of list comprehensions, try them out in python console, and look at output. Here is some of them:

[i for i in [1,2,3,4]]
[i for i in range(10)]
[i**2 for i in range(10)]
[max(4, i) for i in range(10)]
[(1 if i>5 else -1) for i in range(10)]
[i for i in range(10) if i % 2 == 0]
Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-arrays
Python Arrays - GeeksforGeeks
3 weeks ago - Use Python's array module when you need a basic, memory-efficient container for large quantities of uniform data types, especially when your operations are simple and do not require the capabilities of NumPy.
๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ python โ€บ arrays
Python Arrays: Syntax, Usage, and Examples
Ideal for representing grids, tables, and matrices. Python arrays, whether implemented as lists or with the array module, are a fundamental data structure used for storing and manipulating collections of items.
๐ŸŒ
Great Learning
mygreatlearning.com โ€บ blog โ€บ it/software development โ€บ python array & how to use them [with examples]
Python Array & How To Use Them [With Examples]
July 5, 2022 - Homogeneous Data Storage: Arrays store only one data type, making them faster and more memory-efficient than lists for large-scale numeric data. Contiguous Memory Allocation: Arrays allocate memory blocks contiguously, enabling quicker access to elements using index-based lookups. Typecode Mapping: Pythonโ€™s array module requires specifying a typecode to define the type of data: import array arr = array.array('i', [1, 2, 3]) # 'i' = signed int
๐ŸŒ
Real Python
realpython.com โ€บ python-array
Python's Array: Working With Numeric Data Efficiently โ€“ Real Python
December 22, 2023 - In this tutorial, you'll dive deep into working with numeric arrays in Python, an efficient tool for handling binary data. Along the way, you'll explore low-level data types exposed by the array module, emulate custom types, and even pass a Python array to C for high-performance processing.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ array-python-set-1-introduction-functions
Array Module in Python - GeeksforGeeks
August 2, 2025 - For example: For an array of integers ... memory locations. The array() function from Python's array module creates an array with elements of a specified data type....
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ python arrays
r/learnpython on Reddit: Python arrays
March 3, 2025 -

I'm following roadmap.sh/python to learn python. I'm at the DSA section.

I understand the concept of arrays in DSA, but what I don't understand is how to represent them in Python.

Some tutorials I've seen use lists to represent arrays (even though arrays are homogeneous and lists are heterogeneous).

I've seen some other tutorials use the arrays module to create arrays like array.array('i') where the array has only integers. But I have never seen anybody use this module to represent arrays.

I've also seen some tutorials use numpy arrays. Which I don't understand their difference from the normal arrays module.

What should I use to represent arrays?

So far I've solved a couple of arrays exercises using Python lists.

๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_arrays.asp
Python Arrays
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 ...
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ array.html
array โ€” Efficient arrays of numeric values
If less than n items are available, EOFError is raised, but the items that were available are still inserted into the array. ... Append items from the list. This is equivalent to for x in list: a.append(x) except that if there is a type error, the array is unchanged.
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ python_arrays.htm
Python - Arrays
Unlike other programming languages like C++ or Java, Python does not have built-in support for arrays. However, Python has several data types like lists and tuples (especially lists) that are often used as arrays but, items stored in these types of
๐ŸŒ
Python Data Science Handbook
jakevdp.github.io โ€บ PythonDataScienceHandbook โ€บ 02.02-the-basics-of-numpy-arrays.html
The Basics of NumPy Arrays | Python Data Science Handbook
Data manipulation in Python is nearly synonymous with NumPy array manipulation: even newer tools like Pandas (Chapter 3) are built around the NumPy array. This section will present several examples of using NumPy array manipulation to access data and subarrays, and to split, reshape, and join the arrays.
๐ŸŒ
Simplilearn
simplilearn.com โ€บ home โ€บ resources โ€บ software development โ€บ your ultimate python tutorial for beginners โ€บ everything you need to know about python arrays
Everything You Need to Know about Python Arrays
June 14, 2024 - What is an array & why use array in Python? As creating an array means importing it to Python, learn the basic array operations, accessing array elements, & more.
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ stable โ€บ reference โ€บ generated โ€บ numpy.array.html
numpy.array โ€” NumPy v2.4 Manual
See Examples for ndarray.copy. For False it raises a ValueError if a copy cannot be avoided. Default: True. order{โ€˜Kโ€™, โ€˜Aโ€™, โ€˜Cโ€™, โ€˜Fโ€™}, optional ยท Specify the memory layout of the array. If object is not an array, the newly created array will be in C order (row major) unless โ€˜Fโ€™ is specified, in which case it will be in Fortran order (column major).
๐ŸŒ
TechAffinity
techaffinity.com โ€บ home โ€บ how to create, access, slice, change, delete & search python arrays?
Python Arrays & Array Methods | Python Solutions for Businesses
June 16, 2020 - Discussed are some Python arrays & array methods. Hereโ€™s how to declare Python arrays & use Python array append, Python array index, and Python array slice
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ library โ€บ functions.html
Built-in Functions โ€” Python 3.14.3 documentation
2 weeks ago - Without an argument, an array of size 0 is created. See also Binary Sequence Types โ€” bytes, bytearray, memoryview and Bytearray Objects. ... Return a new โ€œbytesโ€ object which is an immutable sequence of integers in the range 0 <= x < 256. bytes is an immutable version of bytearray โ€“ it has the same non-mutating methods and the same indexing and slicing behavior. Accordingly, constructor arguments are interpreted as for ...