[Webinar] Streamline your web hosting managementRegister Today


Python Programming: If Statements

Posted on
13,035 Points
6 Endorsements
Last Modified:
Experience Level: Beginner
Learn the basics of if, else, and elif statements in Python 2.7.

Video Steps

1. Use "if" statements to test a specified condition.

The structure of an if statement is as follows:
if <condition>:         
           do something

Open in new window

2. Use "else" statements to allow the execution of an alternative, if the first condition is not met

The structure of an if, else statement is as follows:
if <condition>:
         do something     
         do something different

Open in new window

3. Use "elif" statements allow for the checking of multiple conditions.

The structure of an if, else, elif statement is as follows:    
if <condition>:
         do something     
elif <another condition>:
         do something different     
         do something completely different

Open in new window


Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Join & Write a Comment

Introduction On September 29, 2012, the Python 3.3.0 was released; nothing extremely unexpected,  yet another, better version of Python. But, if you work in Microsoft Windows, you should notice that the Python Launcher for Windows was introduced wi…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Suggested Courses

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month