Home » Python

True keyword with example in Python

Python True keyword: Here, we are going to learn about the True keyword with example.
Submitted by IncludeHelp, on April 15, 2019

Python True keyword

True is a keyword (case-sensitive) in python, it is a Boolean value (a value of class type bool). True is the result of a comparison operation.

Syntax of True keyword

    True

Example:

    Input:
    x = True

    # print
    print(x)

    Output:
    True

Python examples of True keyword

Example 1: Assign True to a variable, print the value and print type of True.

# python program to demonstrate example of 
# True keyword

# assigning True to a variable
x = True
# printing the value
print("x: ", x)

# printing type of True
print("Type of True:", type(True))

Output

x:  True
Type of True: <class 'bool'>

Example 2: Printing the result of some of the comparison operations.

# python program to demonstrate example of 
# True keyword

a = 10
b = 20

print(a>=10 and b>=20)
print(a==10 and b==20)
print(a!=20 and b!=10)
print(a>5 and b>10)

Output

True
True
True
True


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.