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 760493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:43:28+00:00 2026-05-14T15:43:28+00:00

Is it guaranteed that False == 0 and True == 1 , in Python

  • 0

Is it guaranteed that False == 0 and True == 1, in Python (assuming that they are not reassigned by the user)? For instance, is it in any way guaranteed that the following code will always produce the same results, whatever the version of Python (both existing and, likely, future ones)?

0 == False  # True
1 == True   # True
['zero', 'one'][False]  # is 'zero'

Any reference to the official documentation would be much appreciated!

As noted in many answers, bool inherits from int. The question can therefore be recast as: "Does the documentation officially say that programmers can rely on booleans inheriting from integers, with the values 0 and 1?". This question is relevant for writing robust code that won’t fail because of implementation details!

  • 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-05-14T15:43:29+00:00Added an answer on May 14, 2026 at 3:43 pm

    In Python 2.x this is not guaranteed as it is possible for True and False to be reassigned. However, even if this happens, boolean True and boolean False are still properly returned for comparisons.

    In Python 3.x True and False are keywords and will always be equal to 1 and 0.

    Under normal circumstances in Python 2, and always in Python 3:

    False object is of type bool which is a subclass of int:

        object
           |
         int
           |
         bool
    

    It is the only reason why in your example, ['zero', 'one'][False] does work. It would not work with an object which is not a subclass of integer, because list indexing only works with integers, or objects that define a __index__ method (thanks mark-dickinson).

    Edit:

    It is true of the current python version, and of that of Python 3. The docs for python 2 and the docs for Python 3 both say:

    There are two types of integers: […] Integers (int) […] Booleans (bool)

    and in the boolean subsection:

    Booleans: These represent the truth values False and True […] Boolean values behave like the values 0 and 1, respectively, in almost all contexts, the exception being that when converted to a string, the strings "False" or "True" are returned, respectively.

    There is also, for Python 2:

    In numeric contexts (for example when used as the argument to an arithmetic operator), they [False and True] behave like the integers 0 and 1, respectively.

    So booleans are explicitly considered as integers in Python 2 and 3.

    So you’re safe until Python 4 comes along. 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 506k
  • Answers 506k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Here's an example of dynamically creating module objects using the… May 16, 2026 at 3:48 pm
  • Editorial Team
    Editorial Team added an answer You can't avoid get_by_key_name() or key-related equivalents to check if… May 16, 2026 at 3:48 pm
  • Editorial Team
    Editorial Team added an answer Use a "full" PowerManager.WakeLock like in this post. eg: PowerManager… May 16, 2026 at 3:48 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

List.Add is an instance member. That means it's not guaranteed to be thread-safe. What
Consider the following Java code: volatile boolean v1 = false; volatile boolean v2 =
C# 4 in a Nutshell (highly recommended btw) uses the following code to demonstrate
Profiling shows this is the slowest segment of my code for a little word
Do C conditional statements always return [1 or 0], or do they return [0
A sequence point in imperative programming defines any point in a computer program's execution
I am learning about NServiceBus and MSMQ. I was told that transactional queues in
Any C programmer who's been working for more than a week has encountered crashes
I'm digitally signing a XML document and verifying it on 2 different machines (Sign
We have to use delayed_job (or some other background-job processor) to run jobs in

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.