Python Lists

List

Lists are used to store multiple values in a single variable. Lists are built-in data structures in Python, along with tuple, set, and dictionary.

Lists are created using square brackets [ ].

Lists are mutable data types, meaning they can be modified after creation.

Ordered and Changable

Lists are ordered, which means the items have a defined sequence that will not change. Each element in a list has an index. If you add new items to a list, they are placed at the end.

Lists can be modified by accessing elements using their index.

Allow Duplicates

Lists can contain items with the same value.

Example

Example of a Python List

Output

Output of a Python List Example

List Length

The length of a list is the number of elements it contains, and it can be determined using the len() function.

Example

Example of finding length of a Python List

Output

Output of finding length of a Python List

List Items - Data Types

Items in a list can be of any data type, including integers, floats, strings, and even other lists.

Python List with Various Data Types

List Methods