If else Statement in Python with Examples

Updated: Feb 16


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 we want to print ‘even number’ if the number is even and ‘odd number’ if the number is not even,

We can understand if else statement by following example.

Syntax:

if condition:

statement 1

else:

statement 2

statement 1: This would execute if the given condition is true

statement 2: This would execute if the given condition is false


Flow Chart


Example 1:

num = 22

if num % 2 == 0:

print("Even Number")

else:

print("Odd Number")

Output:

Even Number

Example 2:

a=10

if a>0

print("Positive Number")

else:

print("Negative Number")

Output:

Positive Number



If else Statement Program Video in Python:






12 views0 comments

Recent Posts

See All

Tell () function can be used to get the position of file handle and returns current position of file object where as Seek () function is used to change the position of the file handle to a given speci

Seek () function is used to change the position of the file handle to a given specific position in python. File handle such as a cursor which defines from where the data has to be read or written in t