Home / Python

Condition Objects - Python

Rating: 4.0Blog-star
Views: 2506
by Anjaneyulu Naini
Last modified: January 30th 2021

If you have knowledge of other programming languages, then you would know the importance of conditional statements. Conditional statements are required for taking decisions. Whenever we operate the software, our choice of action decides the next step. A simple example is booking an air ticket. If you want to travel in economy class, you will be presented a different package, whereas if you opt for business class you will be given a different package. So, let’s take a look at the conditional statements available in python.

If you want enrich your career and become a professional in python, then visit Mindmajix - a global online training platform : "python training online"   This course will help you to achieve excellence in this domain

-An else statement can be combined with an if statement. An else statement contains the block of code that executes if the conditional expression in the if statement resolves to 0 or a FALSE value.

Format:

if (expression): code1

else:

code2

EXAMPLE:

a= 7
b=8
if(a>b):
print ‘I am greater than b’ else:
print ‘I am greater than a’

Output :I am greater than a

-To check multiple conditions and run the block of code for the condition that returns ‘true’

Format:

if expression1: code1

elif expression2: code2

elif expression3: code3

else:

code4

EXAMPLE:

a=7
b=7
if(a>b):
print ‘I am greater than b’ elif (b>a):
print ‘I am greater than a’ elif (a==b):
print ‘Hey!! we both are equal’

Output: Hey!! we both are equal

- A simple if statement can be used without any else or else if. Usage of simple if statement means that the lines of code should be executed only if the condition is true.

Format:

if condition : execute the code

EXAMPLE:

a=7
b=7
if(a>b):
print ‘I am greater than b’ print ‘Good Bye’

Output: Good Bye

If you are interested learn python and build a career in it ? Then checkout our python training near your cities

Python Training ChennaiPython Training New YorkPython Training in BangalorePython Training in Dallas

These courses are incorporated with Live instructor-led training, Industry Use cases, and hands-on live projects. This training program will make you an expert in Microsoft Azure and help you to achieve your dream job.

Explore Python Sample Resumes! Download & Edit, Get Noticed by Top Employers!Download Now!

 

About Author

author
NameAnjaneyulu Naini
Author Bio

Anjaneyulu Naini is working as a Content contributor for Mindmajix. He has a great understanding of today’s technology and statistical analysis environment, which includes key aspects such as analysis of variance and software,. He is well aware of various technologies such as Python, Artificial Intelligence, Oracle, Business Intelligence, Altrex etc, Connect with him on LinkedIn and Twitter.