Conditional Statements
In python If else statement is also known as conditional statements to check if the condition is true or false. And it is also known as a decision making statement.
1. If statement - It is the simple decision making statement. In this statement when we execute some lines of code then the block of statement will be executed or not i. e If the condition is true then the block of statement will be executed otherwise not.
2. If…else statement - In if statement if condition is true then it will execute a block of statement and if the condition is false then it won’t. but in this statement there are two blocks . In this statement if the condition is false then execute the else condition.
3. Nested if statement - Nested if in python is placing an if statement inside another if statement. Nested if statement helpful if you want to check another condition inside a condition. Python provides this feature to check multiple conditions in a given program.
4. If-elif ladder - The condition statement are executed from top down. In this if-elif if the if condition is true then the the if block will be executed otherwise not. Then check if the elif condition if it true then it will be executed otherwise not. If none of the condition is true then the else block will be executed.
5. Short hand if statement - Short hand if is also called as one line statement. In python we can write if statement, if else statement and elif statement in one line without indentation. If there is single line statement then we can use short hand if statement.
Comments
Post a Comment