Skip to main content
Practice

list

---
id: list
title: How to Store Ordered Data List
description: Understanding Python Lists and How to Use Them
tags:
- list
- Python
- programming
- data structure
sidebar_position: 1
isPublic: false
---

# How to Store Ordered Data List

In Python, a `List` is a datatype that represents **ordered data**. It allows storing and modifying elements of various data types.

Lists are created by enclosing elements in square brackets `[]` and separating each element with a comma (`,`).

Each element in a list can be accessed by an `Index`.

An index is a number that indicates the **position of a specific element** within a data structure containing sequential elements, such as a list.

Indices in a list start at `0`, with `0` referring to the first element in the list.

```python title="Example of a List"
# Creating a list of integers
numbers = [100, -2, 32, 450]

In the example above, the elements at each index in the numbers list are as follows:

  • numbers[0]: 100

  • numbers[1]: -2

  • numbers[2]: 32

  • numbers[3]: 450


What Data Can Be Stored in a List?

Lists can store various types of data, such as integers, strings, and other lists.

Characteristics of a List
# Creating a list that includes various data types
mixed = [1, "apple", True, 3.14]

In the example above, the mixed list includes elements of various data types such as an integer, string, boolean, and floating-point number.

Moreover, lists can contain other lists as well.

List Containing Various Data Types
mixed_list = [1, "apple", ["Python"]]

In the example above, the third element of mixed_list, i.e., mixed_list[2], includes another list ["Python"].

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.