Woonghee Lee Woonghee Lee - 11 months ago 41
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,)
True == (False,)

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

Answer Source


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.


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