# Create a List with Fruits with Items Banana, apples
# Display the total number of items in the list
# Append the fruit Manago to the list
# display the total number of items in the list
________________________________________________________________________________________
# Create a List with Fruits with Items Banana, apples
# display the list from begining to ending
# display the list from ending to begining
________________________________________________________________________________________
family = ["Mother", "Father"]
print("List is :")
print(family)
print("Total number of items in the list :", len(family))
print(f"_______________________________")
print(f"List in normal order")
print(f"_______________________________")
print("Index : 0 " , family[0])
print("Index : 1 " ,family[1])
print(f"_______________________________")
print(f"List in reverse order")
print(f"_______________________________")
print("Index : -1 " ,family[-1])
print("Index : -2 " ,family[-2])
print(f"_______________________________")
print(f"Appending an item")
print(f"_______________________________")
family.append("Sister")
print("Total number of items in the list :", len(family))
print("Index : 2 " ,family[2])
print(f"_______________________________")
print(f"List in reverse order")
print(f"_______________________________")
print("Index : -1 " ,family[-1])
print("Index : -2 " ,family[-2])
print("Index : -3 " ,family[-3])
family = family + ["Brother"]
print("Total number of items in the list :", len(family))
print(family[-1])
print(family[4])
________________________________________________________________________________________
# Create a list a = ["ONE", "TWO" , "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN"]
# Get all elements in the list
print(a[::])
print(a[:])
# Get elements from index 1 to 4 (excluded)
print(a[1:4])
# Get elements starting from index 2 to the end of the list
b = a[2:]
print(b)
# Get elements starting from index 0 to index 3 (excluding 3th index)
c = a[:3]
print(c)
# Get every second element from the list starting from the beginning
b = a[::2]
print(b)
# Get every third element from the list starting from index 1 to 8(exclusive)
c = a[1:8:3]
print(c)
Comments
Post a Comment