Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8374521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:56:29+00:00 2026-06-09T14:56:29+00:00

I have the following code in python: def update(request, id): success = 0 try:

  • 0

I have the following code in python:

def update(request, id):
  success = 0

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

  if success == 1:
    return render_to_response("success.html")
  else:
    return render_to_response('failure.html')

Is this code a valid way to check the “success” boolean. If the code passes through the try statement, will “success” be changed to 1 or is it remaining at 0?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:56:30+00:00Added an answer on June 9, 2026 at 2:56 pm

    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')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have the following python code: def outer(): string = def inner(): string
I have the following code in Python: def point_to_index(point): if point not in points:
I have wrote following code for a simple problem in Python - def Peu1(numbers):
I have the following python code: class FooMeta(type): def __setattr__(self, name, value): print name,
Kinda knew to Python: I have the following code: def printCSV(output, values, header): 63
consider I have the following code in python module a.py : def func(): obj
I have following python code: def scrapeSite(urlToCheck): html = urllib2.urlopen(urlToCheck).read() from BeautifulSoup import BeautifulSoup
In Python, consider I have the following code: class SuperClass(object): def __init__(self, x): self.x
I have the following Python code: def find_words(letters): results = set() def extend_prefix(w, letters):
I have the following code in python from selenium import webdriver from selenium.webdriver.common.by import

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.