...

Web Technologies - PYTHON

Back to Course

Lesson Description


Lession - #279 Python Arrays



Arrays in Python

Note that Arrays are not built-in to Python, but Python Lists can be used instead.

cars = ["Ford", "Volvo", "BMW"]

print(cars>


Output:
Sorry cannot be displayed py_class_object.jpg Try it here

Arrays

Note: This page demonstrates how to use LISTS as ARRAYS in Python; however, to deal with arrays in Python, you must first import a library, such as NumPy.

Multiple values are stored in a single variable using arrays:

What exactly is an array?

An array is a type of variable that can hold several values at once.
If you have a list of objects (for example, a list of automobile names>
, you could store the cars in separate variables like this:

car1 = "Ford"
car2 = "Volvo"
car3 = "BMW"


But what if you want to search through all of the automobiles to find a specific one? What if you had 300 cars instead of three?

The answer is an array!

Many values can be stored in an array with a single name, and the values can be accessed by referring to an index number.