Python for Testers #20 – How to use If Else in Python

In this Python for Testers Tutorial we will learn how to use If Else in python. It is very important to understand python if else and know how to you can use it in Python programming or selenium with python automation. The if else syntax in Python for a simple if statement is as follows:

if condition :

indented Statement Block (Indentation is important)

As python relies on indentation and not curly braces to define scope as in other language like Java, you can read the above syntax as, If the condition is evaluated to true, then execute the indented statements and if the condition is not evaluated to true, then skip the indented statements.