How to use if statements in Python

If statements are used to control the flow of a program based on a certain condition. In Python, an if statement is written as follows:

if condition:

The condition is an expression that evaluates to either True or False. If the condition is True, the statement(s) will be executed. If the condition is False, the statement(s) will be skipped.

For example:

x = 5
if x > 0:
print(“x is positive”)

In this example, the condition is x > 0, which evaluates to True since x is 5. Therefore, the statement print(“x is positive”) will be executed.