Python True

Contents

Python True

Python True is a keyword used to represent the logical/boolean value of true or 1.

Since, True represents one of the two boolean values, which is returned by boolean expressions, or conditions when the expression/condition evaluates to logically true value.

Examples

For example, in the following example, we take a boolean expression 1 == 1, which always evaluates to logical true. We have assigned this expression to variable x, and print the result to standard output.

Python Program

x = 1 == 1
print(x)
Run Code Copy

Output

True

Assign True to variable

We can assign a value of True to a variable. In the following program, we have assigned the value True to variable x.

Python Program

x = True
print(x)
Run Code Copy

Output

True

Function returns True

Since, it is a value, we can return True from a function, always or during specific conditions.

Python Program

def alwaysTrue():
    return True

x = alwaysTrue()
print(x)
Run Code Copy

Output

True

Summary

In this tutorial of Python Examples, we learned what True keyword is in Python programming, and how to use it under different circumstances.

Related Tutorials

Code copied to clipboard successfully 👍