Is the working of in operator and tuple.index ( ) same ?
Answers
Answered by
2
Answer:
not both are different
Answered by
2
Answer:
Somewhere the working of in operator and tuple.index() is the same as both of them search for a value but it is not exactly the same.
in operator returns true or false whereas tuple.index() returns the position of the value.
in operator
If a specific value is present in the object then it returns true otherwise false.
Example:
tuple = (1, 3, 5, 7, 9)
print(3 in tuple)
print(4 in tuple)
Output:
True
False
tuple.index()
Its searches for a value for the first occurrence and returns its position.
Example:
tuple = (1, 3, 5, 7, 9)
print(tuple.index(3))
print(tuple.index(5))
Output:
1
2
Similar questions
Social Sciences,
2 months ago
Sociology,
2 months ago
English,
4 months ago
Geography,
11 months ago
Math,
11 months ago