IF Statement in Python:

There comes a situation in real life when we need to make some decisions and based on these decisions, we decide what should we do next. Similar situations arise in programming also where we need to make some decisions and based on these decisions, we will execute the next block of code.

Decision making statements in programming languages decides the direction of flow of program execution.

Syntax : import numpy as np

from numpy.random import randn

Example:

Here when I run the Cell 25, X value is less than 1, the If condition is False, so the print statement is Not executed.

Run the cell 25, every time a new random value will be assigned to x.

Iam running this cell until the random value is greater than 1.

Now the X value is greater than 1, so print statement is executed.

If else statement:

Example:

Here X value is less than 1, it went to Else part and printed X is less than 1.

Nested if /Elif:

Example: