Python Tutorial
In previous blog we learn basic concepts about python and datatypes of Python and operators in Python and also we learn the loops in python. The link of the python datatypes blog is pythoncode4you and python loops blog link is pythoncoding4you
In this blog we learn "if-else" statement. In it we also perform the if-else statement programs. So lets learn it.
In Python we use "if" statement, "if-else" statement, "if-elif-else", "nested if-else" statement.
- if Statement
- if-else Statement
- nested if-else Statement
- if-elif-else Statement
1.if Statement
In Python we use "if" statement when we have to check the condition is true and the block of code get executed and print the result and the condition is false then the "if" block is not executed.
Program:
Output:
2.if-else Statement
As we use "if" statement the "if-else" statement is also like it but in "if-else" statement when the condition is true the if block is executed and when the condition is false the else block is executed.
Program:
Output:
3.if-elif-else Statement
The elif is short for else if. In the "elif" statement first check if condition when false then it goes under "elif" block. When all "elif"gets false then it goes under else block.
Program:
Output:
4.nested if Statement
As we seen above "if-else" statement in "nested if-else" statement another if-else under the previous "if-else" statement is known as "nested if-else" statement.
Nice👍👍👍
ReplyDeleteNice information
ReplyDeleteNice...
ReplyDeleteVery nice
ReplyDeleteNice information 👍👍👍👍
ReplyDelete👍👍👍
ReplyDelete