+ 2

How to create list in python?

25th Apr 2021, 3:51 PM
Ravindra Kamble
Ravindra Kamble - avatar
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.
25th Apr 2021, 6:25 PM
Jerry Hobby
Jerry Hobby - avatar
+ 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.
25th Apr 2021, 3:57 PM
KǟrÉšsÉŠmǟ ❄
KǟrÉšsÉŠmǟ ❄ - avatar