Page 140 - TechPluse_C8_Flipbook
P. 140
Function blocks begin with the keyword def followed by the function name and parentheses
( ( ) ).
Any input parameters or arguments should be placed within these parentheses. You can also
define parameters inside these parentheses.
The first statement of a function can be an optional statement—the documentation string of
the function or docstring.
The code block within every function starts with a colon (:) and is indented.
Syntax:
def function_name(parameters):
statement(s)
Program 17: To create a function to check the number is even or odd.
On running the program, we get the following output:
Restart
The if statement is the simplest conditional statement.
The if…elif…else ladder helps us to test multiple conditions and follows a top-down
approach.
Looping statements are very useful and necessary for developing applications.
Python provides two types of looping statements—for and while.
The break is a keyword in Python which is used for bringing the program control out of
the loop.
When a continue statement is encountered inside a loop, control of the program jumps
to the beginning of the loop for next iteration, skipping the execution of rest of the
statements of the loop.
A function is a block of organized and reusable code used to perform a single or related
action.
138 Premium Edition-VIII

