Programming with Python

  1. Home
  2. Docs
  3. Programming with Python
  4. Conditional statements in python
  5. if statement in python

if statement in python

The if statements are the conditional statements in python.

An if statement tests a particular condition; if the condition is true, a statement or set of statement is executed. Otherwise, the statement is ignored.

syntax:-

if conditional statement:
    statements

In if statement indentation plays a major role. If indentation is wrong, indentation error is shown when execute the code.

Make sure to indent all statements in one block at the same level.

e.g.,

a = 5
b = 2
if b < a:
  print("b is less than a")
Output- b is less than a

This is all about if statement in python.

Was this article helpful to you? Yes No

How can we help?