top of page

If elif else statement in python with examples

Updated: Feb 16, 2022


We use the if..elif..else statement when we need to check multiple conditions.

Syntax:

if condition:

statement1

elif condition_2:

statement 2

elif condition_3:

statement 3

..

..

..

else:

statement_n

Example 1:

num = 1234

if 9 < num < 100:

print("Two digit number")

elif 99 < num < 1000:

print("Three digit number")

elif 999 < num < 10000:

print("Four digit number")

else:

print("number is <= 9 or >= 10000")

Output:

Four digit number

Example 2:

x=int(input("Enter the number: "))

if x>0:

print("Positive Number")

elif x<0:

print("Negative Number")

else :

print("Zero")

Output:

Enter the number: 5

Positive Number


If elif else statement video in python:





25 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

bottom of page