Skip to content

List

Python List

Lists are built-in data types that store a collection of ordered values. It’s one of the most flexible, used python data type.

Features that list have

  1. Mutable: Lists are mutable, it’s elements can be modified after after the list has been created.

  2. Ordered: The order in which the elements where added is maintained

  3. Heterogeneous: A list can a contain different data types such as integers, floats, and other data types as well

Creating a list

A list in Python can be created in one of the following ways.

Empty List

An empty list can be created using an empty square brackets [].

Example

example of creating an empty list
my_list = []

A list with values

To create a list place a sequence of comma-separated values within a square bracket.

Example

example of creating a list with values in python
# a list whose elements are of string data type
programming_lang = ["C#", "Golang", "Python", "JavaScript"]
# a list containing a mixed data types
mixed_list = ["Newton", 22]

using the built-in list() function

Example

creating a list using tuple()
# creating an empty list
empty_list = list()
mark_language = "HTML"
# create a list containing a sequence of string characters
chars = list(mark_language)