xxxxxxxxxx
#Creating lists
my_list = [1, "Hello", 3.4, 0, "World"]
my_nested_list = [['Hello', 'World'],[47,39]]
#Accessing lists
my_list[1] # Hello
my_list[-2] # 0
my_list[:3] # [1, "Hello", 3.4]
my_nested_list[1] #[47,39]
my_nested_list[0][1] # World
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)