WHAT IS CONTROL STATEMENTS AND HOW TO USE IN PYTHON PROGRAMMING

CONTROL STATEMENTS

Python provides three selection statements that execute code based on a condition that evaluates to either True or False:
  • The if statement performs an action if a condition is True or skips the action if the condition is False.
  • The if... else statement performs an action if a condition is True or performs a dif erent action if the condition is False.
  • The if... elif... else statement performs one of many different actions, depending on the truth or falsity of several conditions.
Anywhere a single action can be placed, a group of actions can be placed.
Python provides two iteration statements—while and for:

  • The while statement repeats an action (or a group of actions) as long as a condition remains True.
  • The for statement repeats an action (or a group of actions) for every item in a sequence of items.

Keywords

The words if, elif, else, while, for, True and False are Python keywords. Using a keyword as an identifier such as a variable name is a syntax error. The following table lists Python’s keywords.

Python keywords

and
as
assert
async
await
break
class
continue
def
del
elif
else
except
False
finally
for
from
global
if
import
in
is
lambda
None
nonlocal
not
or
pass
raise
return
True
try
while
with
yield

*

Post a Comment (0)
Previous Post Next Post