Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Use if a and b: when both variables need to be truthy. If you mean both must contain Python’s literal Boolean value True, use if a is True and b is True: instead. The right test depends on what “true” means for your values.
Check whether both variables are truthy
Python lets conditions use values other than True and False. In an if statement, if a and b: checks whether each value evaluates as true:
if a and b:
print("Both values are truthy")
This is useful when a value should count as present or enabled according to its type’s truth behavior. For example, a nonempty string or a nonzero number is truthy, while an empty string or zero is not. The Python 3.14.7 built-in types reference describes the rules, including how a class can customize truth testing with __bool__() or, when appropriate, __len__().
Examples of truthy and false values
bool(None) # False
bool(False) # False
bool(0) # False
bool("") # False
bool([]) # False
bool("hello") # True
bool(3) # True
Common false values include None, False, numeric zero, and empty built-in sequences and collections. Most other objects are true unless their class defines different truth behavior.
#1 Best Overall
Require both variables to be exactly True
If each variable must be the Boolean singleton True—not merely a value that behaves as true—use identity checks:
if a is True and b is True:
print("Both are exactly True")
This stricter check rejects values such as 1 and "yes", even though they are truthy. Use it when your requirement specifically calls for Boolean values, rather than when any nonempty or enabled value should pass.
Rank #2
Choose and or or based on the condition
a and brequires both values to be truthy.a or brequires at least one value to be truthy.
For example, use if a or b: when either value is enough. Using or when both must pass changes the condition’s meaning.
Python’s Boolean operators short-circuit and return operands, not necessarily Boolean values: x and y returns x if x is false, otherwise it evaluates and returns y. Likewise, x or y returns x if it is true, otherwise it evaluates and returns y. If you need a Boolean result from an expression, use bool(a and b). These behaviors are documented in the Python 3.14.7 expressions reference.
Write comparisons and compound conditions clearly
Comparisons bind more tightly than not, and, and or. Thus, not a == b means not (a == b). Add parentheses to make a compound condition’s intended grouping clear.
A chained comparison such as a == b == True means a == b and b == True, with the middle expression evaluated once. It does not express the ordinary requirement that both variables be truthy. For that, write a and b; for exact Boolean values, write a is True and b is True.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




