syntax of list in python code example
Example 1: how to create a list in python
new_list = []
item1 = "string1"
item2 = "string2"
new_list.append(item1)
new_list.append(item2)
print(new_list[0])
print(new_list[1])
Example 2: python list
myList = [9, 'hello', 2, 'python']
print(myList[0])
print(myList[-3])
print(myList[:3])
print(myList)
Example 3: list in python
thislist = ["apple", "banana", "cherry"]
print(thislist[1])
Example 4: python list
my_list = [1, "Hello", 3.4, 0, "World"]
my_nested_list = [['Hello', 'World'],[47,39]]
my_list[1]
my_list[-2]
my_list[:3]
my_nested_list[1]
my_nested_list[0][1]