Answering your question:

Are booleans mutable in python?

Yes and no. Variables that are assigned a boolean value are (probably always, and definitely in this case) mutable, yes. They're also not restricted to being assigned boolean values, as variables are not staticly typed.

But the booleans True and False themselves are not mutable. They are singletons that cannot be modified.

Looking at your actual code:

if success = 1:

Is not valid syntax, you want a == there. Also, idiomatically speaking you should not use 0 and 1 for success and failure values you should use True and False. So you should refactor to something like this:

def update(request):
    success = False

    try:
        product = Mattress.objects.get(id=id)
        success = True
    except Mattress.DoesNotExist:
        pass

    if success:
        return render_to_response("success.html")
    else:
        return render_to_response('failure.html')
Answer from Daniel DiPaolo on Stack Overflow
🌐
Real Python
realpython.com › lessons › immutable-builtin-types-numbers-booleans
Looking at Immutable Built-in Data Types: Numbers & Booleans (Video) – Real Python
03:54 And in fact, in Python, there’s only ever one object that’s True and one object that’s False. Because they are immutable, you don’t need to have lots of objects that are equal to True or lots of objects that are equal to False.
Published   October 1, 2024
🌐
PyTutorial
pytutorial.com › are-booleans-mutable-in-python-immutability-explained
PyTutorial | Are Booleans Mutable in Python? Immutability Explained
March 13, 2026 - You can change their contents without creating a new object. Integers, strings, and tuples are examples of immutable types. Booleans belong to this group. In Python, True and False are not just keywords.
🌐
Real Python
realpython.com › python-mutable-vs-immutable-types
Python's Mutable vs Immutable Types: What's the Difference? – Real Python
January 26, 2025 - Here’s a summary of which built-in types are mutable and which are immutable: There are some extra considerations for you to keep in mind about some of the types in this table: Tuples can contain mutable types. Booleans can only hold True or False.
🌐
Scribd
scribd.com › document › 690204832 › UNIT-II
Booleans: Mutable vs Immutable in Python | PDF | Parameter (Computer Programming) | Boolean Data Type
The document discusses mutable and immutable data types in Python. It defines mutable types as those that can be modified after initialization, such as lists and dictionaries, while immutable types like integers and strings cannot be changed after creation. It provides examples of immutable types like numbers, strings, tuples, and frozen sets, as well as mutable types including lists, dictionaries, and sets.
🌐
Python Pool
pythonpool.com › home › blog › python data types | mutable and immutable data types
Python Data Types | Mutable and Immutable Data Types - Python Pool
February 26, 2023 - A Boolean is such a data type that almost every programming language has, and so does Python. Boolean in Python can have two values – True or False.
🌐
University of Toronto
cs.toronto.edu › ~david › course-notes › csc110-111 › 06-memory-model › 03-mutable-data-types.html
6.3 Mutable Data Types
So which data types are mutable and immutable in Python? The non-collection data types int, float, bool, str are all immutable. The collection data types set, list, and dict are all mutable. Data classes are mutable by default. There is a way to define immutable data classes, but that is beyond ...
🌐
Manning
freecontent.manning.com › mutable-and-immutable-objects
Mutable and Immutable Objects | Manning
November 13, 2017 - Most python objects (booleans, integers, floats, strings, and tuples) are immutable. This means that after you create the object and assign some value to it, you can’t modify that value. Definition An immutable object is an object whose value cannot change.
Find elsewhere
🌐
Great Learning
mygreatlearning.com › blog › it/software development › understanding mutable and immutable in python
Understand What is Mutable and Immutable in Python
October 14, 2024 - Objects of built-in type that are ... user to define the characteristics) Objects of built-in type that are immutable are: Numbers (Integer, Rational, Float, Decimal, Complex & Booleans) Strings ·...
🌐
Python Morsels
pythonmorsels.com › mutable-tuples
Mutable tuples - Python Morsels
June 28, 2021 - Don't have an account yet? Sign up here. Tuples in Python are immutable, meaning you cannot mutate them; you cannot change them. Except you can change the value of a tuple... sort of.
🌐
Python Snacks
pythonsnacks.com › p › the-differences-between-mutable-and-immutable-data-types-in-python
The differences between Mutable and Immutable data types in Python
July 3, 2025 - Common immutable data types include: Integers (int) Floating-point numbers (float) Booleans (bool) Strings (str) Tuples (tuple) Mutable objects, on the other hand, are like modeling clay – they can be reshaped and modified after creation without ...
🌐
Readthedocs
python-automation-book.readthedocs.io › en › 1.0 › 03_collection › 05_mutable.html
Understanding Mutable and Immutable Objects in Python — Python for Network Engineer
When you change the value of an ... a new object is created. ssh_timeout += 1 id(ssh_timeout) # Example output: 1513546842672 · None · Booleans (True and False) Strings ·...
🌐
Raushan's Blog
why-dsa.hashnode.dev › python-fundamentals-everything-you-need-to-know-about-data-types-and-objects
Understanding Mutability and Immutability in Python: A Guide to Number
May 19, 2024 - Boolean values True and False can be used in numerical contexts, where True is equivalent to 1 and False is equivalent to 0. ... Understanding the diverse set of numerical and related types in Python helps you choose the right type for your specific needs. While integers, floats, and complex numbers are core numerical types, Decimal and Fraction offer higher precision for specialized tasks. Sets provide unique operations for collections of elements, though they are mutable unlike the immutable number types. Finally, booleans, as a subtype of integers, allow for intuitive use in logical and numerical operations.
🌐
Team Treehouse
teamtreehouse.com › library › python-sets › immutable-data-types
Immutable Data Types (How To) | Python Sets | Treehouse
✨ Earn college credits in Cybersecurity, JS, HTML, CSS and Python · Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll ... Sets can only contain immutable data types. Immutable means the data cannot be changed after it is created, such as strings, integers, and floats.
Published   June 10, 2022
🌐
LinkedIn
linkedin.com › pulse › understanding-mutable-immutable-objects-python-kelsie-merchant
Understanding Mutable and Immutable Objects in Python
May 31, 2020 - For example, if you have a tuple ... means the object cannot be changed. Integers, floats, strings, booleans, and, as mentioned above, frozensets and tuples are all considered immutable....
🌐
Sololearn
sololearn.com › en › Discuss › 1582958 › why-is-int-immutable-and-list-mutable
Why is int immutable and list mutable? | Sololearn: Learn to code for FREE!
I am a python novice and here I was trying to understand what immutability entails. This is what is my understanding so far: (a) In python integers, strings, booleans and tuples are immutable.
🌐
Python documentation
docs.python.org › 3 › reference › datamodel.html
3. Data model — Python 3.14.6 documentation
These are created by numeric literals and returned as results by arithmetic operators and arithmetic built-in functions. Numeric objects are immutable; once created their value never changes.
🌐
Python Tutorial
pythontutorial.net › home › advanced python › python mutable and immutable
Understanding Python Mutable and Immutable Clearly
March 27, 2025 - An object whose internal state can be changed is called a mutable object, while an object whose internal state cannot be changed is called an immutable object. ... User-defined classes can be mutable or immutable, depending on whether their internal state can be changed or not. When you declare a variable and assign its an integer, Python creates a new integer object and sets the variable to reference that object:
🌐
InventiveHQ
inventivehq.com › home › blog › python › mutable vs immutable objects in python
Mutable vs Immutable Objects in Python: Lists, Tuples ...
December 22, 2025 - Any operation that appears to change an immutable object actually creates a new object in memory. The following Python data types are immutable: bool – Boolean values (True, False) integer – Whole numbers ·
Address   2305 Historic Decatur Rd, Suite 100, 92106, San Diego
🌐
Readthedocs
jfine-python-classes.readthedocs.io › en › latest › subclass-int.html
Subclassing int — Objects and classes in Python tutorial
Once made they cannot be changed. They are called immutable types. >>> y = 'abc' >>> y[0] = 'A' Traceback (most recent call last): TypeError: 'str' object does not support item assignment · We will use enumerated integers as an example in this section. In Python, booleans are an example of ...