As a Python developer with over a decade of experience, I’ve encountered many situations where I needed to check if multiple conditions were false before proceeding. Checking if both variables are false in Python is a common task, especially when working with flags, user inputs, or managing program flow.
Even though it sounds simple, there are multiple ways to perform this check in Python. Each method has its own advantages and use cases. In this article, I’ll walk you through the most effective and readable ways to check if both variables are false in Python. You’ll see full code examples and learn when to use each approach.
Check If Both Variables Are False in Python
In real-world Python projects, you often deal with boolean variables that indicate the state of something, like user authentication status, feature toggles, or error flags. For example, imagine you’re building a US-based web app and you want to proceed only if two conditions are both false, such as:
- is_user_logged_in is False
- has_active_subscription is False
This check helps you control the program flow effectively.
Method 1: Use the and Operator in Python
The simplest and most direct way to check if both variables are false in Python is to use the and operator. This operator returns True only if both operands are true. Since we want to check if both are false, we negate the variables.
Here’s how I do it:
is_user_logged_in = False
has_active_subscription = False
if not is_user_logged_in and not has_active_subscription:
print("Both variables are false. Access denied.")
else:
print("At least one variable is true. Access granted.")You can refer to the screenshot below to see the output.

- not is_user_logged_in checks if is_user_logged_in is false.
- not has_active_subscription checks if has_active_subscription is false.
- The
andoperator ensures both are false before executing the block.
This method is easy and very readable, which is why I use it most often.
Method 2: Use Equality Comparison
Another way I’ve found useful is comparing both variables directly to False using the equality operator ==. This can sometimes make the intention clearer, especially for beginners.
is_user_logged_in = False
has_active_subscription = False
if is_user_logged_in == False and has_active_subscription == False:
print("Both variables are false. Access denied.")
else:
print("At least one variable is true. Access granted.")You can refer to the screenshot below to see the output.

While this works perfectly, I personally prefer the first method because it’s more Pythonic and concise.
Method 3: Use Python all() Function
Python’s built-in all() function can check if all elements in an iterable are true. Since we want to check if both are false, we can invert the variables first or check if all are false by passing their negation.
Here’s how I apply it:
is_user_logged_in = False
has_active_subscription = False
if all(not var for var in [is_user_logged_in, has_active_subscription]):
print("Both variables are false. Access denied.")
else:
print("At least one variable is true. Access granted.")You can refer to the screenshot below to see the output.

This method is handy when you have more than two variables to check. It scales well and keeps your code clean.
Method 4: Use a Custom Function in Python
In larger projects, I sometimes create a helper function to check if multiple variables are false. This improves code reuse and readability.
def are_both_false(var1, var2):
return not var1 and not var2
is_user_logged_in = False
has_active_subscription = False
if are_both_false(is_user_logged_in, has_active_subscription):
print("Both variables are false. Access denied.")
else:
print("At least one variable is true. Access granted.")This way, you can call are_both_false() anywhere in your code without repeating the logic.
Real-World Example: User Access Control
Let me share a practical example from a US-based e-commerce platform I worked on. We needed to restrict access to premium content unless the user was logged in and had an active subscription.
Here’s how I checked if both conditions were false to block access:
def check_access(is_logged_in, has_subscription):
if not is_logged_in and not has_subscription:
return "Access Denied: Please log in and subscribe."
return "Access Granted: Welcome!"
user_logged_in = False
user_subscription_active = False
message = check_access(user_logged_in, user_subscription_active)
print(message)This simple check saved us from unauthorized access and improved user experience.
Tips for Checking Boolean Variables in Python
- Always prefer not var over var == False for clarity and Pythonic style.
- Use all() or any() when checking multiple variables to keep your code scalable.
- Write helper functions for repeated logic to improve maintainability.
- Remember that Python treats many values as false in boolean context (e.g., None, 0, “”). If you want to check strictly for the boolean False, use is False.
Checking if both variables are false in Python is a common task that you can perform in multiple ways. From using simple and operators to leveraging functions like all(), each method has its place depending on your project needs.
I recommend starting with the and operator combined with not for clarity and readability. As your codebase grows, consider helper functions or the all() function to keep your code clean and maintainable.
You may also like to read:
- Write a Python Program to Remove Duplicates From a Dictionary
- Python Create Empty Dictionary
- Check If Two Dictionaries Are Equal in Python
- Python Copy Dict Without One Key

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.