Category Python

Python Nested If Else Statement

When we place an ‘if statement’ inside another ‘if statement’, it is a nested if statement in Python. It is a very common to use in Python programming. Python nested if statement is useful when we want to check for…

Python If Elif Else Statement

Flowchart diagram of if elif else in Python

If elif else in Python is a multi-way decision control statement, which is a combination of if, else if, and else statements. When we need to choose one of several possible alternatives, we use elif statement along with if statement.…

If Else in Python

Flowchart diagram of Python if else statement

If else in Python is a two-way conditional statement or double selection statement. It tests a conditional expression and executes one of two blocks of code, depending on the result. In other words, an if else statement first evaluates the…

If Statement in Python

Flow chart diagram of if statement in Python

An if statement in Python is the simplest decision-making statement that allows the programmer to execute a block of statements only if some condition is true. We use if statement in the Python program to compare data and to make…

Ternary Operator in Python

An example of ternary operator in Python

Python 2.5 introduced a shorthand operator, known as ternary operator. This operator requires three operands and performs conditional test based on a condition being true or false. Python supports only one ternary operator. It is also known as conditional expression…