Codectionary / Developer documentation / Python

True

In Python, True is a built-in constant that represents the boolean value of true. Alongside False, True enables logical and conditional operations. It's a fundamental keyword used throughout Python programming for decision-making, loops, comparisons, and boolean logic. True plays a key role in if statements, while loops, and logical expressions.

About Python

Python is a general-purpose programming language with readable syntax and a large library ecosystem. It is useful for automating tasks, analysing data and building services or machine-learning tools.

  • Automation
  • Data and AI
  • Backend services
Created by
Guido van Rossum at CWI
First released
1991 ยท first public release
Version / standard
Python 3.14

Current stable release line. Patch releases provide further fixes.

In the real world

  • Netflix: Data workflows and platform tooling
  • Spotify: Klio audio and data pipelines
  • LinkedIn: Offline generative-AI workflows

Facts checked 8 September 2026. Links open the sources; examples describe specific products or documented uses.

Syntax

True

Examples

Direct Assignment

Assigning True directly to a variable for boolean flags and state management.

is_authenticated = True
feature_enabled = True

if is_authenticated:
    print("User is logged in")

if feature_enabled:
    print("Feature is active")

Conditional Statements

Using True in if statements to control program flow based on conditions.

age = 25
is_adult = age >= 18  # Evaluates to True

if is_adult:
    print("Access granted")
else:
    print("Access denied")

# Multiple conditions
has_permission = True
is_verified = True

if has_permission and is_verified:
    print("You can proceed")

While Loops

Using True to create continuous loops that run until explicitly broken.

count = 0

while True:
    response = input("Type 'quit' to exit: ")
    if response.lower() == 'quit':
        break
    count += 1
    print(f"You have entered {count} commands")

print("Loop exited")

Logical Operations

Combining True with boolean operators (and, or, not) for complex logic.

# AND operator - both must be True
result1 = True and True   # True
result2 = True and False  # False

# OR operator - at least one must be True
result3 = True or False   # True
result4 = False or False  # False

# NOT operator - inverts the value
result5 = not True        # False
result6 = not False       # True

# Complex expression
is_weekend = True
has_money = True
is_sunny = False

go_out = is_weekend and has_money and (is_sunny or not is_sunny)
print(f"Should go out: {go_out}")

Comparisons

How comparisons return True when the evaluated condition meets the criteria.

# Numeric comparisons
print(10 > 5)      # True
print(100 >= 100)  # True
print(5 == 5)      # True

# String comparisons
print("hello" == "hello")  # True
print("abc" < "xyz")       # True

# Membership testing
fruits = ["apple", "banana", "orange"]
print("apple" in fruits)  # True

# Type checking
print(isinstance(42, int))  # True

Input Validation

Using True in validation scenarios to verify user input or data integrity.

def validate_email(email):
    # Simple validation checks
    has_at = '@' in email
    has_dot = '.' in email
    is_long_enough = len(email) > 5
    
    is_valid = has_at and has_dot and is_long_enough
    return is_valid

# Test the validation
user_email = "user@example.com"

if validate_email(user_email) == True:
    print("Email is valid")
    print("Proceeding with registration")
else:
    print("Invalid email format")

Best practices

  • Use True directly in conditions rather than comparing (if is_active: instead of if is_active == True:)
  • Choose descriptive boolean variable names that read like questions (is_valid, has_permission, can_access)
  • Remember that True is case-sensitive - it must be capitalized in Python
  • Avoid redundant comparisons with True/False - the variable itself is already boolean
  • Use True in while loops with break conditions for continuous processes
  • Leverage True in complex boolean expressions with and, or, not operators for readable logic

At a glance

Purpose
Scripting and general-purpose applications
File extension
.py
Runs in
Python interpreter
Usually used with
Python standard library and packages

Specifications & further reading

Related Python documentation

False
False is Python's built-in constant representing the boolean value false. It's the logical opposite of True and is essential for conditional logic, loop control, and boolean operations. False is used to indicate negative conditions, failed validations, or when something is not the case. Understanding False is crucial for writing effective control flow in Python programs.
None
None is Python's built-in singleton value that represents the absence of a value or a null result. It is its own type (NoneType) and is commonly used as a default parameter value, a placeholder before a variable is assigned real data, or a function's implicit return value when nothing is explicitly returned. Unlike 0, an empty string, or an empty list, None specifically means 'no value here', not 'an empty value'.
Variables & Assignment
Variables in Python are names bound to values, created the moment you first assign to them - there's no need to declare a type in advance, since Python is dynamically typed. A single variable can be reassigned to a completely different type later in the program. Python also supports several convenient assignment patterns, including assigning multiple variables at once and using augmented assignment operators.
print()
print() is Python's built-in function for writing output to the console. It can accept any number of values, automatically converts them to strings, and separates them with a space by default. Its sep and end keyword arguments give fine control over formatting, making print() useful for everything from simple debugging to building formatted console output.