Last modified: Mar 13, 2026 By Alexander Williams
Are Booleans Mutable in Python? Immutability Explained
This is a common question for new Python developers. The short answer is no. Python booleans are immutable. This article explains what that means and why it matters.
Understanding Mutability vs. Immutability
First, let's define the terms. Mutability refers to whether an object can be changed after it is created.
A mutable object can be altered. An immutable object cannot be changed. Any operation on an immutable object creates a new object.
Lists and dictionaries are classic examples of mutable types. You can change their contents without creating a new object.
Integers, strings, and tuples are examples of immutable types. Booleans belong to this group.
Python Booleans: A Singleton Instance
In Python, True and False are not just keywords. They are singleton objects of the bool class. This class is a subclass of int.
True is essentially the integer 1.False is the integer 0. Because integers are immutable, booleans inherit this property.
This design means there is only one instance of True and one instance of False in the entire Python runtime. This is efficient and prevents confusion.
For a deeper dive into how booleans work, see our Python Booleans Guide: True, False, Logic.
Proof of Immutability: The id() Function
You can prove immutability using Python's built-in id() function. This function returns the memory address of an object.
If the id changes after an operation, a new object was created. If it stays the same, the original object was modified.
Let's test this with a boolean.
# Check the id of the True object
true_id = id(True)
print(f"Initial id of True: {true_id}")
# Try to perform an operation (addition)
result = True + 5 # True acts as 1
print(f"Result of True + 5: {result}")
# Check the id of True again. It should be unchanged.
print(f"id of True after operation: {id(True)}")
print(f"Are the ids the same? {true_id == id(True)}")
Initial id of True: 140736036590720 # Your number will differ
Result of True + 5: 6
id of True after operation: 140736036590720
Are the ids the same? True
The id of True did not change. The addition operation used the value of True (which is 1) but did not alter the True object itself. It created a new integer object (6).
What Happens When You "Assign" a New Value?
You might think you can change a boolean variable. Look at this code.
flag = True
print(f"Initial value: {flag}")
print(f"Initial id: {id(flag)}")
# Reassign the variable
flag = False
print(f"\nNew value: {flag}")
print(f"New id: {id(flag)}")
Initial value: True
Initial id: 140736036590720
New value: False
New id: 140736036590544
The id changed. This is the key point. The variable flag is just a name, a label.
First, it was attached to the immutable True object. The reassignment flag = False detached the label from True and attached it to the immutable False object.
You changed what the variable points to, not the boolean object itself. The objects True and False remained untouched.
Implications for Your Code
Understanding boolean immutability helps you write better code.
1. Predictable Behavior: You never have to worry about a function secretly changing your True value to something else. It's impossible.
2. Memory Efficiency: Since there's only one True and one False, Python doesn't waste memory creating new ones.
3. Safe Comparisons: Using is for identity checks with booleans is safe and sometimes faster than == because you're checking if it's the exact singleton object.
def check_status(active):
# This is safe because True/False are singletons
if active is True:
return "System is ON"
else: # active is False
return "System is OFF"
print(check_status(True))
print(check_status(False))
System is ON
System is OFF
However, for general equality, using == is the standard and more readable practice. The is operator is for checking object identity.
Common Pitfall: Confusing Assignment with Mutation
Beginners often confuse reassigning a variable with mutating an object. Compare a boolean with a list.
# IMMUTABLE Boolean (Reassignment)
bool_var = True
bool_var = False # Label moved. True object unchanged.
# MUTABLE List (In-place mutation)
list_var = [1, 2]
list_var.append(3) # The original list object is changed.
print(list_var)
[1, 2, 3]
With the list, the object's internal state changed. With the boolean, we simply pointed the variable name at a different, pre-existing object.
This concept is crucial for understanding how Python passes arguments to functions. Immutable objects like booleans are passed "by object reference," but since they can't change, the function cannot modify the original.
Conclusion
Python booleans are immutable. The objects True and False are fixed, singleton instances that cannot be altered.
When you write my_flag = False, you are binding the name my_flag to the immutable False object, not creating a new or changeable boolean.
This immutability leads to reliable and efficient code. It ensures that a True value anywhere in your program is always the same True.
Remember, mutability is about the object itself, not the variable name. This distinction is fundamental to mastering Python's data model. For more on boolean logic and operations, revisit our Python Booleans Guide.