Tuple

 Simple program with tuple:

tuple = [1, 4, 5]
print(tuple)

Output:








Progarm with  tuple methods:

tuple = [1, 4, 5, 6, "the value ", 4, 3, 4, 2, 4, 5, 3, 4]
print(tuple)

# count
# to count a particular value
print(tuple.count(4))

# index
# to find out the index number
print(tuple.index(6))

 Output:






Program with tuple using user input

f1 = input("enter fruit 1 ")
f2 = input("enter fruit 2 ")
f3 = input("enter fruit 3 ")
f4 = input("enter fruit 4 ")
f5 = input("enter fruit 5 ")
f6 = input("enter fruit 6 ")
f7 = input("enter fruit 7 ")
f8 = input("enter fruit 8 ")

fruit_tuple = [f1, f2, f3, f4, f5, f6, f7, f8]
print(fruit_tuple)

Output:













No comments:

Post a Comment