Woonghee Lee Woonghee Lee - 1 year ago 93
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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download