Python True Keyword

Last Updated : 21 Jul, 2026

True is one of Python's two Boolean constants (True and False) and represents a logical true value. It is commonly used in conditional statements, loops, Boolean expressions, and logical operations to control program flow. In numeric contexts, True behaves like the integer 1.

Python
status = True

if status:
    print("Access granted")

Output
Access granted

Data Type of True

Python
print(type(True))

Output
<class 'bool'>

Explanation:

  • True belongs to the Boolean (bool) data type.
  • The bool type has only two values: True and False.

Using True in Conditional Statements

The True keyword is commonly used in conditional statements. When the condition evaluates to True, the code inside the if block is executed.

Python
x = 10
is_greater = x > 5

if is_greater:
    print("x is greater than 5")

Output
x is greater than 5

Explanation:

  • The expression x > 5 evaluates to True and is stored in the variable is_greater.
  • Since the condition is True, the if block is executed.

Using True in an Infinite Loop

The True keyword is commonly used with the while loop to create an infinite loop. The loop continues executing until it is terminated explicitly using a statement such as break.

Python
count = 0

while True:
    print(count)
    count += 1

    if count == 5:
        break

Output
0
1
2
3
4

Explanation:

  • while True creates an infinite loop because the condition always evaluates to True.
  • The count variable is incremented during each iteration.
  • When count becomes 5, the break statement terminates the loop.

Using True in Logical Operations

The True keyword is frequently used with logical operators such as and, or, and not to evaluate Boolean expressions.

Python
print(True and True)
print(True or False)
print(not True)

Output
True
True
False

Explanation:

  • True and True returns True because both operands are True.
  • True or False returns True because at least one operand is True.
  • not True returns False because the not operator reverses the Boolean value.

Using True in Comparisons

The True keyword can be compared with other values using comparison and identity operators. Since bool is a subclass of int, True is equal to 1 but remains a Boolean object.

Python
one = 1

print(True == one)
print(True is True)

Output
True
True

Explanation:

  • True == 1 returns True because True has the numeric value 1.
  • True is True returns True because both references point to the same Boolean constant.

Note: Use == to compare values and is to compare object identity.

Using True in Arithmetic Operations

The bool data type is a subclass of int in Python. As a result, True behaves like the integer 1 in arithmetic expressions.

Python
print(True + 5)
print(True * 3)
print(True - 1)

Output
6
3
0

Explanation:

  • True + 5 evaluates to 6 because True is treated as 1.
  • True * 3 evaluates to 3 because 1 × 3 = 3.
  • True - 1 evaluates to 0 because 1 - 1 = 0.

Note: Although Boolean values can be used in arithmetic expressions, they are primarily intended for logical operations and conditional statements.

Truthy and Falsy Values

In Python, every object has an associated truth value. The Boolean constant True and most non-empty or non-zero values are considered truthy, meaning they evaluate to True in Boolean contexts. Values such as False, 0, None, and empty collections are considered falsy.

Python
values = [True, 1, "Python", [1, 2], 0]

for value in values:
    print(f"{value!r}: {bool(value)}")

Output
True: True
1: True
'Python': True
[1, 2]: True
0: False

Explanation:

  • True, non-zero integers, non-empty strings, and non-empty lists are truthy values.
  • The integer 0 is a falsy value.
  • Truthy and falsy values are commonly used in conditional statements and loops.

Common Truthy Values: True, non-zero numbers, non-empty strings, non-empty lists, non-empty tuples, non-empty dictionaries, non-empty sets, and most user-defined objects.

Comment