equality operator with tuple: 'a', 'b' == ('a', 'b')

Viewed 40

A tuple can be made without parenthesis.

t1 = 'a', 'b'
t2 = ('a', 'b')
t1 == t2

Output:

True

But when tried this

'a', 'b' == ('a', 'b')

Output:

('a', False)

Can someone explain the Output in the second part?

2 Answers

, as a tuple operator has extremely low precedence. This means that if you don't put parentheses, it will be one of the last operators to be grouped. So, 'a', 'b' == ('a', 'b') is not ('a', 'b') == ('a', 'b'), but rather 'a', ('b' == ('a', 'b')).

The comparison 'b' == ('a', 'b') is evaluated before ,, so the result is

'a', ('b' == ('a', 'b'))
('a', False)
Related