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?
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?
, 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)