If else Statement in Python

Updated: May 18, 2020


if statements is execute a certain block of Python code when a particular condition is true. Whenever If..else statements are execute true and false condition both. if condition is true and a different set of statements if condition is false. For example, you want to print ‘even number’ if the number is even and ‘odd number’ if the number is not even, we can accomplish this with the help of if..else statement.

Syntax:

if condition:

statements1

else:

statments2

statements1: This would execute if the given condition is true

statements1: This would execute if the given condition is false


Flow Chart


Example:

num = 22

if num % 2 == 0:

print("Even Number")

else:

print("Odd Number")

Output:

Even Number




8 views0 comments

Recent Posts

See All

Python Modules

A module is a file containing Python definitions and statements. A module can characterize functions, classes and variables. A module can likewise incorporate runnable code. Gathering related code int

 

9555593818

Thakurdwara, Uttar Pradesh 244601, India

  • Facebook
  • Twitter
  • LinkedIn