Defining a list in Python is really quite simple. All that’s needed is to give a name to the list and then initialize by providing it with values.
myExampleList = [element1, element2, element3,...]
myStringList = ["Learn", "python","with","Educative"] print(myStringList)
Similar to most other programming languages, lists in Python are zero indexed.
myIntList = [1, 3, 5 ,2, 4]
We will use
myIntList to get the first element from the list, that is, 1.
myIntList = [1,3,5,2,4] print(myIntList)
Note: You can create an empty list:
lst = or
lst = list()
View all Courses