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
-
Mutable: Lists are mutable, it’s elements can be modified after after the list has been created.
-
Ordered: The order in which the elements where added is maintained
-
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
my_list = []
A list with values
To create a list place a sequence of comma-separated values within a square bracket.
Example
# 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 an empty list empty_list = list()
mark_language = "HTML"
# create a list containing a sequence of string characters chars = list(mark_language)