Introduction

The world is often a complicated place to write a program that executes sequentially. No matter what project you’re working on, it involves skipping few statements and then executing a series of statements recursively.

This is where conditional statements in any language come to light; often, most languages have an if statement as a fundamental step to begin with, so does Python. Without any further delay, let’s explore the different ways to write conditional statements in Python.


If Statement

In simple words, if statement is a combination of two components: expression and statement.

**expression: **It’s the condition that needs to evaluated and return a boolean (true/false)value.

statement: statement is a general python code that executes if the **expression **returns true.

The syntax of if statement looks, as shown below:

if <expression>:
    <statement>

Always remember colon(:) following the expression is mandatory, to put it into the action we can do something as shown below:

simple if statement in python

We can also execute multiple statements if the expression returns true, Have a look:

#python #python3 #python-for-beginners #programming #conditional-statements

Python for Beginners —  Control Statements
1.20 GEEK