Codectionary / Developer documentation / Python

False

False is Python's built-in constant representing the boolean value false. It's the logical opposite of True and is essential for conditional logic, loop control, and boolean operations. False is used to indicate negative conditions, failed validations, or when something is not the case. Understanding False is crucial for writing effective control flow in Python programs.

Syntax

False

Examples

State Management

Using False to track states and flags in your program.

is_logged_in = False
has_notifications = False

if is_logged_in:
    print("Welcome back!")
else:
    print("Please log in")  # This will print

if not has_notifications:
    print("No new notifications")  # This will print

Boolean Comparisons

How various comparisons evaluate to False in different scenarios.

# Numeric comparisons
print(5 > 10)      # False
print(3 == 7)      # False
print(100 < 50)    # False

# String comparisons
print("hello" == "world")  # False
print("abc" > "xyz")       # False

# List membership
numbers = [1, 2, 3]
print(5 in numbers)  # False

# Empty checks
print(bool([]))      # False - empty list
print(bool(""))      # False - empty string
print(bool(0))       # False - zero

Logical Operations

Combining False with boolean operators to create complex conditions.

# AND operator
result1 = False and True   # False
result2 = False and False  # False

# OR operator
result3 = False or True    # True
result4 = False or False   # False

# NOT operator
result5 = not False        # True

# Real-world example
is_admin = False
has_special_access = False
is_verified = True

can_view_panel = is_admin or (has_special_access and is_verified)
print(f"Can access admin panel: {can_view_panel}")  # False

Validation and Error Checking

Using False to indicate validation failures or error states.

def check_password_strength(password):
    # Check various requirements
    has_length = len(password) >= 8
    has_number = any(char.isdigit() for char in password)
    has_upper = any(char.isupper() for char in password)
    
    is_strong = has_length and has_number and has_upper
    return is_strong

# Test with weak password
user_password = "hello"
result = check_password_strength(user_password)  # Returns False

if result == False:
    print("Password is too weak")
    print("Requirements: 8+ characters, number, uppercase")

Loop Control

Using False to control loop execution and exit conditions.

searching = True
attempts = 0
max_attempts = 3

while searching:
    attempts += 1
    user_input = input(f"Attempt {attempts}: Enter the code: ")
    
    if user_input == "1234":
        print("Correct code!")
        searching = False  # Exit loop
    elif attempts >= max_attempts:
        print("Too many attempts")
        searching = False  # Exit loop
    else:
        print("Wrong code, try again")

print("Process complete")

Best practices

  • Write conditions positively when possible (if is_valid: instead of if not is_invalid:)
  • Use "not" operator for better readability (if not is_active: instead of if is_active == False:)
  • Remember that many values are "falsy" in Python (0, empty strings, empty lists, None)
  • Initialize boolean flags with False when starting in a negative state
  • Use False explicitly when you need to distinguish from None or 0
  • Choose meaningful variable names that clearly indicate what False represents

At a glance

Purpose
Scripting and general-purpose applications
File extension
.py
Runs in
Python interpreter
Usually used with
Python standard library and packages

Specifications & further reading

Related Python documentation

True
In Python, True is a built-in constant that represents the boolean value of true. Alongside False, True enables logical and conditional operations. It's a fundamental keyword used throughout Python programming for decision-making, loops, comparisons, and boolean logic. True plays a key role in if statements, while loops, and logical expressions.
None
None is Python's built-in singleton value that represents the absence of a value or a null result. It is its own type (NoneType) and is commonly used as a default parameter value, a placeholder before a variable is assigned real data, or a function's implicit return value when nothing is explicitly returned. Unlike 0, an empty string, or an empty list, None specifically means 'no value here', not 'an empty value'.
Variables & Assignment
Variables in Python are names bound to values, created the moment you first assign to them - there's no need to declare a type in advance, since Python is dynamically typed. A single variable can be reassigned to a completely different type later in the program. Python also supports several convenient assignment patterns, including assigning multiple variables at once and using augmented assignment operators.
print()
print() is Python's built-in function for writing output to the console. It can accept any number of values, automatically converts them to strings, and separates them with a space by default. Its sep and end keyword arguments give fine control over formatting, making print() useful for everything from simple debugging to building formatted console output.