New Training: Conditionals and Loops in Python
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?
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).