+ 2
How to create list in python?
2 Answers
+ 4
MyListInt = [ 0, 1, 2 ]
MyListStr = [ "Zero", "One", "Two" ]
MyListAll = [ MyListInt, MyListStr, 3, 4, 5, "three", "four", "five"]
print(MyListInt)
print(MyListStr)
print(MyListAll)
You will see how lists with lists inside are displayed with additional [] to show lists inside of lists.
+ 9
A list is created by placing all the items (elements) inside square brackets [] , separated by commas. It can have any number of items and they may be of different types (integer, float, string etc.). A list can also have another list as an item.