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

  • Home
  • SEARCH
  • 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 6826659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:10:25+00:00 2026-05-26T22:10:25+00:00

When storing a bool in memcached through python-memcached I noticed that it’s returned as

  • 0

When storing a bool in memcached through python-memcached I noticed that it’s returned as an integer. Checking the code of the library showed me that there is a place where isinstance(val, int) is checked to flag the value as an integer.

So I tested it in the python shell and noticed the following:

>>> isinstance(True, int)
True
>>> issubclass(bool, int)
True

But why exactly is bool a subclass of int?

It kind of makes sense because a boolean basically is an int which can just take two values but it needs much less operations/space than an actual integer (no arithmetics, only a single bit of storage space)….

  • 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-26T22:10:26+00:00Added an answer on May 26, 2026 at 10:10 pm

    From a comment on http://www.peterbe.com/plog/bool-is-int

    It is perfectly logical, if you were around when the bool type was
    added to python (sometime around 2.2 or 2.3).

    Prior to introduction of an actual bool type, 0 and 1 were the
    official representation for truth value, similar to C89. To avoid
    unnecessarily breaking non-ideal but working code, the new bool type
    needed to work just like 0 and 1. This goes beyond merely truth value,
    but all integral operations. No one would recommend using a boolean
    result in a numeric context, nor would most people recommend testing
    equality to determine truth value, no one wanted to find out the hard
    way just how much existing code is that way. Thus the decision to make
    True and False masquerade as 1 and 0, respectively. This is merely a
    historical artifact of the linguistic evolution.

    Credit goes to dman13 for this nice explanation.

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

Sidebar

Related Questions

This code compiles: private static void Main(string[] args) { bool? fred = true; if
Problem, there's no method: bool ChangePassword(string newPassword); You have to know the current password
This code works: class Test { public: Test(string name) : _name(name) {}; bool operator()()
Is there any method? My computer is AMD64. ::std::string str; BOOL loadU(const wchar_t* lpszPathName,
Currently, I have some code as follows template<typename Type> Type* getValue(std::string name, bool tryUseGetter
I am using the below mentioned library to create a barcode which is storing
I am using dictionary for storing ID,otherID and bool value. Unfortunately it compares array
Currently I am studying Standard Template Library (STL). In this program I am storing
I have this sample code: struct A { bool test() const { return false;
My application is storing contact information. User can edit them through DataGridView and so

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.