True

In Python, the True keyword represents a boolean value indicating a truth value in logical operations and expressions. It’s defined as a built-in constant with a value of 1 and is a subclass of int.

Python True Keyword Examples

Here’s an example demonstrating how the True keyword can be used in Python:

Python
>>> is_adult = True
>>> if is_adult:
...     print("They're more than 18 years old")
... else:
...     print("They're less than 18 years old")
...
They're more than 18 years old

In these examples, the conditional check the value of is_adult. Because it’s True, the if clause runs.

Python True Keyword Use Cases

  • Logical operations and comparisons to indicate a true condition.
  • Control flow statements like if and while to dictate the execution of code blocks.
  • Boolean flags in functions to toggle features or options.
  • Default argument value in functions and methods

Tutorial

Python Booleans: Use Truth Values in Your Code

In this tutorial, you'll learn about the built-in Python Boolean data type, which is used to represent the truth value of an expression. You'll see how to use Booleans to compare values, check for identity and membership, and control the flow of your programs with conditionals.

intermediate python

For additional information on related topics, take a look at the following resources:


By Leodanis Pozo Ramos • Updated Jan. 13, 2025 • Reviewed by Dan Bader