Python Conditionals and Control flow of a program are the concepts to discussed. Visit http://www.placementraja.com for full tutorial.
Python conditionals are the conditional statements that determines which block of code will be executed.
Python Conditionals or Conditional statements in python :
1) if (expression) statement
2) elif (expression) statement
3) else statement
Expression should return any Boolean value that is either True or False. So, expression should be Boolean expression
Types of Boolean expressions are :
1) Boolean expressions with Comparison operators ( == , != ,less than and greater than symbols )
2) Boolean expressions with Logical operators ( and , or , not )
Examples ::
Here a,b are any variable like numbers etc..
a == b
a != b
a and b
a or b
!a or !b
Python Control Flow depends on :
1 Python conditionals or python conditional statements
2 Loops like for loop, while loop etc..
3 Functions
Lets see python conditionals thoroughly
if expression:
statement
elif expression:
statements
else:
statement
The indented bunch of statements after if conditional statement or elif conditional statement will be executed if and only if expression is true.
elif (else if) will be checked only if conditional expression fails
if can be followed by if or elif statements
elif conditional should precede if conditional
else conditional will be executed if both if conditional and elif conditional fails.
Follow us : / placementraja
Subscribe : / @placementraja4232