nextRound
TechnologiesCoding ProblemsBookmarksLearning PathsLogin
nextRound
TechnologiesCoding ProblemsBookmarksLearning PathsLogin
nextRound

AI-powered interview preparation platform. Practice with curated questions, mock interviews, and personalized learning paths to crack your dream tech interview.

Quick Links

  • Technologies
  • Mock Interviews
  • Saved Questions
  • Pricing

Company

  • About Us
  • Contact Us

Legal

  • Privacy Policy
  • Terms of Use

© 2026 nextRound. All rights reserved.

Questions
5 of 6
1Why does id() sometimes appear to be reused between two seemingly unrelated objects?
2Why does modifying a list while iterating over it lead to unexpected behavior?
3What is the difference between copy.copy() behavior on a custom object with __copy__ defined versus one without it?
4What will happen when a closure captures a loop variable, and why do all closures created in the loop end up referencing the same final value?
5Why can True == 1 and False == 0 evaluate to True in Python?
6What is monkey patching, and what risks does it introduce in production codebases?
PythonPython
Basics
Control Flow and Functions
Data Structures
Comprehensions & Functional Programming
Iterators, Generators & Decorators
Object-Oriented Programming
Exception Handling & Debugging
Concurrency & Parallelism
Performance & Optimization
Testing
Security
Modules, Packaging & Environment
Type Hinting & Modern Python
System Design & Architecture with Python
Best Practices & Design Patterns
Edge Cases & Tricky Interview Questions
05 / 06

Why can True == 1 and False == 0 evaluate to True in Python?

Difficulty: 3/10
Bool, Int, Subclassing, Equality

bool is a subclass of int, so True and False are the integers 1 and 0

In Python, bool is a subclass of int. True is a bool object with the integer value 1, and False is a bool object with the integer value 0. Because bool inherits from int, comparisons and arithmetic treat them as integers. That is why True == 1 is True, and also why True + True equals 2. This is a deliberate design choice to allow booleans to be used in numeric contexts. The trade-off is that it can surprise developers coming from languages where booleans are distinct types. You can check the exact type with type(x) is bool. In most code, this behavior is harmless, but it matters when you use a boolean as a dict key or in a set, because True and 1 collide.

  1. 1

    bool is a subclass of int. True and False are the only instances.

  2. 2

    True == 1 and False == 0 evaluate to True because of the integer values.

  3. 3

    True + True == 2, True * 5 == 5, and sum([True, True]) == 2.

  4. 4

    Because hash(True) == hash(1) and they compare equal, True and 1 collide in dicts and sets.

  5. 5

    Common mistake: using a boolean as a dict key and being surprised that 1 overwrites True.

  6. 6

    Common mistake: assuming type(True) is int; it is bool.

  7. 7

    Version note: this has been true since Python 2.3 and is consistent in Python 3.

Scenario Questions

0-2 years experience

  1. 1Why does True + True equal 2?
  2. 2How do you check if a value is exactly a boolean?

2-5 years experience

  1. 1You use True and 1 as separate keys in a dict and one overwrites the other. Why?
  2. 2You need to distinguish between 1 and True in a validation function. How do you do it?

5-8 years experience

  1. 1You are designing an API that accepts flags as either bool or int. How do you handle the ambiguity?
  2. 2A serialization format loses the distinction between True and 1. How do you preserve it?

8+ years experience

  1. 1Explain how bool's subclassing of int affects type checking, hashing, and arithmetic in a large codebase.
  2. 2Design a type-safe configuration system that treats booleans and integers distinctly despite Python's type system.

Follow-up Questions

  • How do True and 1 behave differently in a dict?
  • How can you check whether a value is a boolean rather than an integer?
Sharethis question

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.