Skip to content
Tutorials Center
My learning

Topics

Python Reference ยท Built-in Functions

Python built-in constants

Reference for Python's built-in constants: True, False, None, Ellipsis (...), NotImplemented and __debug__, with examples, identity checks and pitfalls.

Python has a handful of constants that are always available and cannot be reassigned: True, False, None, Ellipsis (written ...), NotImplemented and __debug__. The first three are keywords; Ellipsis and NotImplemented are singleton objects in the built-in namespace. Because each exists exactly once, compare them with is.

The site module also adds quit, exit, copyright, credits and license for interactive sessions. They are not available when Python runs with -S and should not be used in programs.

Python
x is None
x is not True

Try it

Python True, False and None

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Python Ellipsis, NotImplemented and __debug__

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Reference

Constant Type Meaning
True bool Boolean true; equal to 1.
False bool Boolean false; equal to 0.
None NoneType The absence of a value. Returned by functions with no return.
Ellipsis / ... ellipsis A placeholder used in slicing (NumPy), type hints and stub bodies.
NotImplemented NotImplementedType Returned by binary special methods to say "I don't support this operand".
__debug__ bool True unless Python runs with -O; controls assert.

Usage notes

  • Use is for None, True and False checks that matter: if x is None. Plain truthiness (if not x) also catches 0, "" and [], which is often a bug when None has a special meaning.
  • bool is an int subclass. True + 1 is 2, and sum() over booleans counts them. True == 1 but True is not 1.
  • None is falsy, has no attributes except the usual object ones, and is the default return value. It cannot be assigned to.
  • ... is a real value. def f(): ... is a legal empty body, handy in stubs, protocols and abstract methods. Prefer pass for "intentionally nothing".
  • NotImplemented is not an exception. Return it (do not raise it) from __eq__, __add__ and similar so Python can try the other operand's reflected method. Raising NotImplementedError is the different tool for abstract methods. Using NotImplemented in a boolean context is deprecated (a DeprecationWarning since 3.9; an error in 3.14).
  • __debug__ cannot be assigned. assert statements are removed when optimization is on.
  • Related singletons: an empty tuple(), small integers and some strings may be shared, but never rely on is for them.