<

Python Programming: If Statements

Posted on
13,163 Points
563 Views
6 Endorsements
Last Modified:
Community Pick: Many members of our community have endorsed this article.
Editor's Choice: This article has been selected by our editors as an exceptional contribution.
Experience Level: Beginner
2:21
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     
else:
         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     
else:
         do something completely different

Open in new window

6
Author:Dototot
0 Comments

Suggested Videos

Data can be kept in different media, Sometimes, the data need to be extracted, transformed or loaded in different ways. For this article, I'm going to demonstrate some of the popular ways of importing JSON data into MS SQL Server.
This article presents an AutoHotkey (V1) script that detects when a USB drive is inserted or removed. It displays a pop-up dialog and makes a logfile entry in each case. It provides a system tray (notification area) icon with context menu choices to…

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month