<

Python Programming: If Statements

Posted on
13,076 Points
476 Views
6 Endorsements
Last Modified:
Awarded
Experience Level: Beginner
2:22
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

Featured Post

Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
A guide on the process of automating change or gathering data from multiple Cisco IOS devices. If this can help you - please use it. God knows we all need a few extra minutes in our day.

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month