New Skills

New Training: Conditionals and Loops in Python

by Team Nuggets
New Training: Python Operators picture: A
Follow us
Published on May 11, 2021

In this 6-video skill, CBT Nuggets trainer Ben Finkel covers the first control flow elements of Python which are conditionals (if-then-else) and looping. Watch this new Python training.

Learn Programming and Development with one of these courses:

This training includes:

  • 6 videos

  • 55 minutes of training

You’ll learn these topics in this skill:

  • Conditionals and Loops in Python

  • Branching Code with Conditionals

  • Iterating Code with While Loops

  • Iterating Code with For Loops

  • Conditional and Loop Control

  • Creating the Game Hangman

How Do IF Statements Work in Python?

All programming languages have a way to control the flow of a program. The flow of an application is the path in which code will take based on certain criteria. Though some programming languages, like JavaScript, can be difficult to manage flow due to how those languages are designed, all programming languages use a basic syntax to control flow. They implement something called an IF statement. Python isn't any different.

An IF statement evaluates the value of a variable or object to determine whether an action should be performed. Here's an example:

IF (x == 0 ) THEN x=x+1

In this case, that IF statement is evaluating the value of X. If X equals zero, then it increases the value of X to one. We can also use an ELSE clause with that IF statement for additional actions. For instance, you could add an ELSE statement to the end of that IF statement to increment the value of X by two. So, if X is any other value than zero (EG. It has a value of one), the code will increase the value of X by two (EG. It will add 2 to the current value of one for X).


Download

By submitting this form you agree to receive marketing emails from CBT Nuggets and that you have read, understood and are able to consent to our privacy policy.


Don't miss out!Get great content
delivered to your inbox.

By submitting this form you agree to receive marketing emails from CBT Nuggets and that you have read, understood and are able to consent to our privacy policy.

Recommended Articles

Get CBT Nuggets IT training news and resources

I have read and understood the privacy policy and am able to consent to it.

© 2024 CBT Nuggets. All rights reserved.Terms | Privacy Policy | Accessibility | Sitemap | 2850 Crescent Avenue, Eugene, OR 97408 | 541-284-5522