Python Tutorial Python Advanced Python References Python Libraries

Python if Keyword



The Python if keyword is used to create a block of conditional statements which executes only when the condition is true.

Syntax

if condition:
  statements         

Flow Diagram:

Python If Loop

Example:

In the example below, the if code block is created which executes only when the variable i is divisible by 3.

i = 15
if i % 3 == 0:
  print(i," is divisible by 3.")

The output of the above code will be:

15 is divisible by 3.

❮ Python Keywords