list in in python code example

Example 1: creating a list in python

myList = [value,value,value] #note that you can use any amount of value
#you don not have to use value

Example 2: python list

# example of list in python

myList = [9, 'hello', 2, 'python']

print(myList[0]) # output --> 9
print(myList[-3]) # output --> hello
print(myList[:3]) # output --> [9, 'hello', 2]
print(myList) # output --> [9, 'hello', 2, 'python']

Example 3: list in python

myfavouritefoods = ["Pizza", "burgers" , "chocolate"]
print(myfavouritefoods[1])
#or
print(myfavouritefoods)

Tags:

Cpp Example