Computer Science, asked by swatantrabhrdwj, 3 months ago

Is the working of in operator and tuple.index ( ) same ?​

Answers

Answered by ishita2172
2

Answer:

not both are different

Answered by dreamrob
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