Skip to main content

Using Python Conditional Expressions

Hands-On Lab

 

Photo of Keith Thompson

Keith Thompson

DevOps Training Architect II in Content

Length

00:30:00

Difficulty

Beginner

We need to constantly evaluate a condition of some kind to determine what action to take or what value to assign to a variable we'll use later in our program. In the situation where we only have an if and an else, and the body of each branch contains only one expression, then we're able to use a conditional expression. Conditional expressions can be used to succinctly express a simple conditional. In this hands-on lab, we'll be refactoring an existing script by rewriting the simple conditional statements as conditional expressions. The following is a prerequisite for feeling comfortable completing this lab: - Conditional expressions.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.