Page 220 - Robotics and AI class 10
P. 220
for i in range(len(flowers)):
if s==flowers[i]:
print(s, " found at index number ",i)
break
else:
print("Sorry' Not Found")
Tuples in Python
In the previous chapter, you have learned about list. Similar to list, a tuple is a sequence of values enclosed in
parentheses and its indices start with 0. Unlike list, tuple cannot be changed which means it is immutable. In this
chapter, we will discuss how to create, access and perform operations on tuples.
Creation of Tuples
To create a tuple, write different values and separate them with comma. You can put the comma-separated values
between the parentheses ‘( )’. Parentheses (round bracket) indicate the start and end of the tuple.
Tuple contains any number of elements of heterogeneous type (integer, float, string, list, etc).
Example of tuple:
tup1=('sst', 'chemistry', 2010, 2022); #tuple with dissimilar items
tup2=(1, 2, 3, 4, 5 ); #tuple with similar items
tup3=(1, 2.5, 3.6, 4, 5 ); #t 50, tup1 is treated to be of type int.
Program 1: To create a tuple.
On running the above program, you will get the following output:
218 Touchpad Robotics & Artificial Intelligence-X

