if, if-else, if-elif in Python Programming | Decision-making Statements in Python
◾️To make decisions in python we have Decision-making statements.👇
◾️The Decisions making statements in python are:
▪️ if
▪️ if-else
▪️ if-elif
🔵IF-Statement in Python
▪️ if statements are used to check whether the given conditions are true or false.
▪️ In python, to indicate the block of code Indentation is used.
▪️️️ Each line must be indented by the same amount in a block of code.
◾️ eg:👇
◼️if condition:
▪️ statements if true # (print() function to print true statements)
▪️ A colon (:) is used in python to make the code more readable and separate
the different parts of expressions.
▪️ INDENTATION is used to represent a block of code in python.
▪️ (==) equal to the operator is used to compare two entities. (entry or value).
🔵ELSE Statements
▪️ an else statements is often used with if statements.
▪️ in the case when the condition inside if evaluates to false, the statements under the else statements are evaluated.
▪️ else is always written after if statements.
◾️NOTE: for is not a decision making statement.
🔵ELIF Statements
▪️ if we want to check multiple conditions we can use elif statements.
▪️ Elif will always come after if statement, it cannot exist individually.
▪️ In the case of if-elif blocks, the conditions will be tested until a condition is found to be true.
▪️ if all the conditions evaluate to false then the else block will be executed.
Question: An else statement cannot exist individually, it should always be
preceded by an if statements.
Answer: is TRUE.
Learn Python for 👈 at👉 DDSRY.COM👈
Follow on Instagram to Learn Python:
Follow on Social Media DDSRY — Python Programming
Facebook -> https://www.facebook.com/ddsry21/
Twitter -> https://twitter.com/DDSRY21
Linkedin -> https://www.linkedin.com/in/deepak-dashrath-yadav-ddsry-5a5452197/