r/PythonLearning • • 7d ago

Python Boolean

I'm having some trouble understanding Python boolean logic, it’s so simple to let it be confusing. Can anyone explain it to me in their own language?

2 Upvotes

14 comments sorted by

View all comments

2

u/ConsiderationNo9044 7d ago

There are two boolean values: True and False. You usually compare them using two operators, and and or. They mean exactly as they do in plain English.

True and True = True, because both values are True.

True and False = False, because one value is False, and and means both must be true.

True or False = True, because one value is True, and or means one value must be True. You can probably guess the result of False or False.

Any non-zero number is Truthy, meaning it represents True, while zero represents False. Any non-empty strings and collections are also Truthy.

1

u/saikat_hossen 7d ago

Thanks, I think I get it now. One more favor, can explain in which type of problem solving this is used? I learn something better once I get it’s core reasons.

2

u/baubleglue 6d ago
if answer == "yes": 
    # do something 
else: 
    # do something else

1

u/saikat_hossen 5d ago

Makes sense, thanks