xxxxxxxxxx
# 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']
xxxxxxxxxx
list = ['apple', 4, 'banana', 'bat', 0.44]
print(list)
#it will print all items in the list
xxxxxxxxxx
myfavouritefoods = ["Pizza", "burgers" , "chocolate"]
print(myfavouritefoods[1])
#or
print(myfavouritefoods)
xxxxxxxxxx
mylist = [] # creating an empty list
# appending values entered by user to list
for i in range(5):
print("Enter value of n[", i, "]")
mylist.append(input())
# printing final list
print(mylist)
xxxxxxxxxx
fruits = ['apple', 'banana', 'mango', 'cherry']
for fruit in fruits:
print(fruit)
xxxxxxxxxx
[1, 'hi', 'Python', 2]
[2]
[1, 'hi']
[1, 'hi', 'Python', 2, 1, 'hi', 'Python', 2]
[1, 'hi', 'Python', 2, 1, 'hi', 'Python', 2, 1, 'hi', 'Python', 2]
xxxxxxxxxx
myList = ["Test", 419]
myList.append(10)
myList.append("my code")
print(myList)