Learn practical skills, build real-world projects, and advance your career

Branching with if , else and elif

One of the most powerful features of programming language is branching the ability to make decisions and execute a different set of statements based on whether one or more conditions are true.

The if statement

In python, branching is implemented using the if statement, which is written as follows

if condition:
statement1
statement2

a_number = 34
if a_number % 2 == 0:
    print("We're inside an if block")
    print('The given number {} is even.'.format(a_number))
We're inside an if block The given number 34 is even.
jovian.commit()
[jovian] Updating notebook "pk810850/untitled" on https://jovian.ai [jovian] Committed successfully! https://jovian.ai/pk810850/untitled