Search This Blog

Wednesday, 15 December 2021

Nested IF statement in python

 

 Python Nested If Statement

simple web creator

We can use nested if statements for situations where we want to check for a secondary condition if the first condition executes as true. For this, we can have an if-else statement inside of another if-else statement. Let’s look at the syntax of a nested if statement:

if expression1:
   statement(s)
   if expression2:
      statement(s)
   elif expression3:
      statement(s)
   elif expression4:
      statement(s)
   else:
      statement(s)
else:
   statement(s)

lets run the following example :

a=10
if a>=20:
    print "Condition is True"
else:
    if a>=15:
        print "Checking second value"
    else:
        print "All Conditions are false"
output of above example :
All Conditions are false.

No comments:

Post a Comment

Sentiment Analyzer using NLP and Python - Practical Guide How to - Ai dev Surya

Unlocking Insights: NLP Project for Sentiment Analysis Natural Language Processing (NLP) is revolutionizing how computers understan...