Go Premium for a chance to win a PS4. Enter to Win


Python Programming: If Statements

Posted on
13,019 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
This article will show, step by step, how to integrate R code into a R Sweave document
Suggested Courses

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month