Decision making is fundamental in making a program. All programming languages provide in-built structure for it and Python is not exception.
In this post, I will explain decision making using if else statements.
Syntax
if expression:
Example of expressions
x > 4
x < 4
x == 4
In Python you will write if x > 4 :
Like, C/C++ and Java it does not use parenthesis, however, Python uses a colon(:).
It would be better to write a program to understand.
x=5 # x is initialized
if x > 4:
print(“This is true”)
Output: This is true
if x < 4:
print(“This is true”)
else:
print(“This is false”)
Output: This is false