# Search function with parameter elements name
# and the value to be searched
def search(Tuple,n):
for i in range(len(Tuple)):
if Tuple[i] == n:
return True
return False
# Main program
# list which contains both string and numbers in a tupple.
Tuple= (1, 2, 'sachin', 4, 'Geeks', 6)
n = 'sachin'
if search(Tuple, n):
print("Found")
else:
print("Not Found")
output
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>>
== RESTART: C:/Users/student/AppData/Local/Programs/Python/Python36-32/q.py ==
sachin
Found
>>>
>>>
== RESTART: C:/Users/student/AppData/Local/Programs/Python/Python36-32/q.py ==
5
Not Found
>>>
No comments:
Post a Comment