Python Arrays
gocourse.in Maintenance

We'll be back soon

Our CDN (cdn.gocourse.in) is currently unreachable. Some images, JavaScript, or CSS files may not load properly.

Estimated downtime: ~30 minutes

Python Arrays

Kishore V

Python Arrays (Lists)

An array is a data structure that allows you to store multiple values in a single variable. Instead of creating many separate variables, you can store all values together in one collection.

Instead of creating many separate variables like this:

You can store all values together in one array (which Python calls a list):

['Pen', 'Pencil', 'Eraser']

This makes your code cleaner, easier to manage, and more efficient—especially when working with large amounts of data.

Creating an Array (List)

In Python, arrays are created using square brackets [].

['Apple', 'Banana', 'Mango', 'Orange']

Accessing Array Elements

Each element in an array has an index number, starting from 0.

Apple Mango

Modifying Array Elements

Array elements can be changed by assigning a new value to a specific index.

['Apple', 'Grapes', 'Mango', 'Orange']

Length of an Array

Use the len() function to find how many elements are in an array.

Total items: 4

Note: The highest index value is always length - 1.

Looping Through an Array

You can iterate through all elements using a for loop.

Fruit: Apple Fruit: Banana Fruit: Mango Fruit: Orange

Adding Elements to an Array

Use the append() method to add a new element at the end.

['Apple', 'Banana', 'Mango', 'Orange', 'Pineapple']

Removing Elements from an Array

Remove by Index (pop())

['Apple', 'Banana', 'Orange'] ['Banana', 'Orange']
Our website uses cookies to enhance your experience. Learn More
Accept !