Python If-else statements
Decision making is the most important aspect of almost all programming languages. As the name suggests, decision making allows us to run a particular block of code for a particular decision. Here, decisions are made on the validity of special circumstances. Condition checking is the backbone of decision making.
In Python, decision making is done by the following statements.
Statement | Description |
---|---|
If Statement | If the statement is used to test a specific situation. If the condition is true(satisfy), a block of code (if-block) will be executed. |
If - else Statement | The if-statement is the same as the if statement except for the fact that it also provides a block of code to check the false state of the condition. If the condition provided in the statement is false, another statement will be executed. |
Nested if Statement | Nested if statement enables us to use if? The statement inside an external statement. |
Perhaps the most well-known statement type is the
if
statement. For example:There can be zero or more
elif
parts, and the else
part is optional. The keyword ‘elif
’ is short for ‘else if’, and is useful to avoid excessive indentation. An if
… elif
… elif
… the sequence is a substitute for the switch
or
case
statements found in other languages.
Python If-else statements
Reviewed by Sk Jha
on
October 24, 2019
Rating:
No comments: