Woonghee Lee Woonghee Lee - 1 month ago 7
Python Question

What is difference between if (False,) and True == (False,)

I learned python 3 last year, but I have barely experience.

I am reviewing about tuple again.

I would like to figure out difference between

if (False,)
and
True == (False,)


Since
if (False,):
is true, but
True == (False,)
is false, I am very confused.

Answer

1.

The boolean value of a tuple is True if it has contents, if it is empty it is False. Because (False,) is a tuple with one element it's boolean value is True.

2.

You are comparing a tuple to a bool, that will always result in False.

Comments