thatisvivek
thatisvivek

Reputation: 915

Tuple comparison gives different result with and without explicit parenthesis

I was comparing two tuples for equality using below expression.

>>> (1, 2, 3) == 1, 2, 3
(False, 2, 3)

I was expecting it will give True. However, below expression works as expected.

>>> a = (1, 2, 3)
>>> b = 1, 2, 3
>>> 
>>> a == b
True

I am unable to understand this behavior. I am using Python 3.6.8

Upvotes: 2

Views: 61

Answers (1)

John Anderson
John Anderson

Reputation: 38892

The (1, 2, 3) == 1, 2, 3 is defining a tuple where the first element is the value of the expression (1, 2, 3) == 1, which is False.

Upvotes: 3

Related Questions