CONTROL STRUCTURES
Python Control Structures
Python Control Structures are Selection Statements and Iterative Statements
Selection Statements: if statement, if-else statement, if-elif-else statement, nested-if statement.
Iterative Statements: while loop, for loop, break statement, continue statement, pass and else statements used with loops.
if statement
if statement is used to test a specific expression. If the expression is true, a block of code (if-block) will be executed. The expression is any valid logical condition which can be either evaluated to true or false.
Syntax
• if expression:
Set of statements
If statemet |
If-else statement
When “if statement “ is false, then the else statement will be executed.
• Syntax
if expression:
#set of statements
else:
#another set of statements (else-block)
if-else statemet |
if-elif-else statement
The elif statement is used to check multiple expressions and execute the specific block of statements depending upon the true condition among them.
Syntax
if expression 1:
# set of statements
elif expression 2:
# set of statements
elif expression 3:
# set of statements
else:
# set of statements
Nested-if statement if statements inside if statements is called nested if statements. • syntax if exp: Statemets If exp2: Statements Else: statemets |
Comments
Post a Comment