Python True Keyword

The True keyword in Python is basically a Boolean value. There are two boolean values, that are True and False. The True is basically a result of:

  • a comparison operation
  • or any other logical expression whose value evaluates in the form of True/False

For example:

a = 10
b = 20
c = 10

print(a==c)
print(a<b)

The output is:

True
True

Python True Keyword Example

The True is a result of boolean operation. That is, if expression(s) of boolean operation evaluates to be True, then the condition evaluates to be True. Here is an example demonstrates it:

print("Enter any Two Values: ", end="")
a = input()
b = input()

x = a==b
if x:
    print("\nBoth values are equal")
else:
    print("\nBoth values are not equal")

print("\nThe value of x =", x)

The snapshot given below shows the sample run of above program, with user input codescracker as first and second value:

python true keyword

Python Online Test


« Previous Tutorial Next Tutorial »

Follow/Like Us on Facebook




Subscribe Us on YouTube