Decision Making in Python in Hindi | Lecture 7 | Python Tutorial | Mayank Gupta

Опубликовано: 06 Декабрь 2024
на канале: Code House
3,069
74

This Python Tutorial in Hindi by Mayank Gupta will teach you if, if-else, if-elif-else statements, Nested if, Using if statement in List.
Today's Subtopics :
1. if statement
2. if-else statement
3. if-elif-else statement
4. Nested if
5. Using if statement in List.
6. Test Your skills

1. if statement
If the boolean expression evaluates to TRUE, then the block of statement(s) inside the if statement is executed.
Body starts with an indentation and the first unindented line marks the end.

2. if-else statement
If the condition is True, body of if statement is executed. And if the condition is False, body of else statement is executed.
Syntax :
if expression:
statement(s)
else:
statement(s)

3. if-elif-else statement
It allows us to check for multiple expressions.The if block can have only one else block. But it can have multiple elif blocks. If the condition for if is False, it checks the condition of the next elif block and so on.If all the conditions are False, body of else is executed.
Only one block among the several if, elif, else blocks is executed according to the condition.

4. Nested if
We can have a if, elif, else statement inside another if, elif, else statement. This is called nesting.
Any number of these statements can be nested inside one another.
Indentation is the only way to figure out the level of nesting.

5. Using if statement in List.

6. Test Your skills
x=25
if(x >= 0):
if(x==0):
print(“Number is zero”)
else:
print(“Positive Number”)
else:
print(“Negative Number”)

Please Like, Comment, Share and Subscribe to my Channel.

Thank you
Mayank Gupta