fruit_tuple = (“apple”,“banana”,“strawberry”,“orange”)
Creates a variable name called “fruit_tuple” which stores four pieces of fruit within it. The
round brackets define this group as a tuple and therefore the contents of this collection of
data cannot be altered while the program is running.
print(fruit_tuple.index(“strawberry”))
Displays the index (i.e. the numeric key) of the item “strawberry”. In this example it
will return the number 2 as Python starts counting the items from 0, not 1.
Do'stlaringiz bilan baham: |