xxxxxxxxxx
my_list = ['p', 'r', 'o', 'b', 'l', 'e', 'm']
# Output: True
print('p' in my_list)
# Output: False
print('a' in my_list)
# Output: True
print('c' not in my_list)
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 = ["Test", 419]
myList.append(10)
myList.append("my code")
print(myList)
xxxxxxxxxx
# Creating a List
grocery_list = ["apple", "watermelon", "chocolate"]
# Appending items to a list
grocery_list.append("milk")
# Changing an item on the list
grocery_list[1] = "apple juice"
# Deleting an item on the list
grocery_list.remove("watermelon")
# Sort list in alphabetical order
grocery_list.sort()
# Joining lists
utensils = ["fork", "spoon", "steak knife"]
list = grocery_list + utensils
# Printing the lists
print(*list, sep=", ")
xxxxxxxxxx
#list is data structure
#used to store different types of data at same place
lst = ['this is str', 12, 12.2, True]
#There are some operations on list that made life easier.
print(lst[1]) # 12
print(lst[-2]) # 12.2
print(lst[:-1]) # Reversed list
print(lst[1:4]) # [12, 12.1, True]
print(lst[::2]) # [12, True]