VOOZH about

URL: https://www.geeksforgeeks.org/python/python-lists/

⇱ Python Lists - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Python Lists

Last Updated : 16 Jun, 2026

List is a built-in data structure used to store an ordered collection of items. They are dynamic, resizable and capable of storing multiple data types.

  • Mutable: list elements can be changed, updated, added, or removed after the list is created.
  • Ordered: elements maintain the order in which they are inserted.
  • Index-based: elements are accessed using their position, starting from index 0.
👁 a_
Above image demonstrates that a list can contain elements of different data types.

Creating a List

Lists can be created in several ways, such as using square brackets [], the list() constructor or by repeating elements.

1. Using Square Brackets: Square brackets [] are used to create a list directly.


Output
[1, 2, 3]
['apple', 'banana']

2. Using list() Constructor: A list can also be created by passing an iterable (such as tuple, string or another list) to the list() constructor.


Output
[1, 2, 3, 'apple', 4.5]
['G', 'F', 'G']

3. Creating List with Repeated Elements: A list with repeated elements can be created using the multiplication (*) operator.


Output
[2, 2, 2, 2, 2]
[0, 0, 0, 0, 0, 0, 0]

Internal Representation of Lists

Python list stores references to objects, not the actual values directly.

  • The list keeps memory addresses of objects like integers, strings or booleans.
  • Actual objects exist separately in memory.
  • Modifying a mutable object inside a list changes the original object.
  • Reassigning an immutable object creates a new object instead of changing the old one.

Output
1
[1, 2, 2, 'Python']

Explanation:

  • a[0] accesses the first element of the list.
  • list contains integers and a string, showing that Python lists can store multiple data types.

Accessing Elements

Elements in a list are accessed using indexing. Python uses zero-based indexing, meaning a[0] represents the first element. Negative indexing is also supported, where -1 accesses the last element.


Output
10
30

Adding Elements

Elements can be added to a list using the following methods:

1. append(): Adds an element at the end of the list.


Output
[1, 2, 3]

2. insert(): Adds an element at a specific position.


Output
[1, 2, 3]

3. extend(): Adds multiple elements to the end of the list.


Output
[1, 2, 3, 4]

Updating Elements

Since lists are mutable, elements can be updated by assigning new values using their index.


Output
[10, 25, 30, 40, 50]

Removing Elements

Elements can be removed from a list using the following methods:

1. remove(): Removes the first occurrence of an element.


Output
[1, 3]

2. pop(): Removes the element at a specific index or the last element if no index is specified.


Output
[1, 2]

3. del statement: Deletes an element at a specified index.

[1, 3]

4. clear(): removes all items.


Output
[]

Iterating Over Lists

Lists can be iterated using loops, allowing operations to be performed on each element.


Output
apple
banana
cherry

Nested Lists

A nested list is a list that contains another list as its element. It is commonly used to represent matrices or tabular data. Nested elements can be accessed by chaining multiple indexes.


Output
[1, 2]
3

To know more, please refer to this article: List comprehension

Related Articles:

Comment
Article Tags: