To initialize a list in Python, you can use the square brackets []
for an empty list or provide elements inside the brackets to create a list with initial values.
In this example,
[]
to create an empty list and assign it to the variable empty_list
.empty_list = []
print("Empty List:", empty_list)
Empty List: []
In this example,
[]
and provide elements inside the brackets to create a list with initial values.fruits
.fruits = ["Apple", "Banana", "Cherry"]
print("List with Elements:", fruits)
List with Elements: ['Apple', 'Banana', 'Cherry']
In this tutorial, we learned How to Initialize a List in Python language with well detailed examples.