top of page
Search
techskill065

if statement in Python



Decision making structures needs the programmer must specify one or more conditions to be evaluated or tested by the programme, as well as a statement or statements to be executed if the condition is found to be true, and optionally, further statements to be executed if the condition is found to be false.




Why should you utilize Python's Decision Making Statement?




It is employed to determine if a statement or a block of statements will be performed or not, i.e., if a condition is true, a block of statements will be executed; otherwise, it will not. After examination, the condition will be either true or false.



In programming languages, decision-making statements determine the course of programme execution.


if statement

if-else statement

if-elif statement


if statement in Python


The if statement in Python is used to test a condition and decide whether or not to execute a block of statements based on the result of that condition. The if statement examines the supplied condition before deciding whether or not to execute a block of statements. If True, the block of statements will be executed; if False, the block of statements will be ignored. The if statement's execution path is as follows.




The if statement in Python has the following general syntax.


Syntax

if condition:

Statement_1

Statement_2

Statement_3


# python program to illustrate If statement

i = 20

if (i < 15):

print("20 is greater than 15")

print("I am Not in if")

Output:


I am Not in if




When we define an if statement, we must only use indentation to specify the block of sentences. A sequence of white spaces form the indentation. The amount of white-spaces is flexible in this case, but all statements must utilise the same number.


Conclusion

Here , we learned about decision making and if statement in python. Visit blog - To learn details decision making statements in python.


1 view0 comments

Comments


Post: Blog2_Post
bottom of page