2. Functions def
¶
We learned some Python functions:
len
,int
,float
,print
, andinput
.Now we will create our own functions.
I use
def
to define the function andreturn
to return a value.There are functions that do not return anything.
Print output (drag lower right corner to resize)
|
Activity: CodeLens 2.1 (cl_l20_2a_en)
This function returns
True
if the parameterx
is even,False
otherwise.Note that, unlike what we have seen so far, these lines of code will not be executed immediately.
It is necessary to call the function to execute them.
2.1. Example¶
Define a function
factorial
Print output (drag lower right corner to resize)
|
Activity: CodeLens 2.1.1 (cl_l20_2b_en)
You have attempted 1 of 2 activities on this page