Define…
def
statement followed by
a colon (:
)Example:
Parameters are components of your function that can vary based on user input. Example:
return
statementreturn
statement is providedExample:
#
), can be
included in your code but are not run""" """
) and are placed on the line following the
function definitionArguments can be supplied to functions in two ways:
for
: Repeats an action over a series of itemswhile
: Repeats an action until a given condition is
satisfiedfor
loopfor
repeats an action for every
element in an objectfor
worksSo what is going on here?
for
loop looks at what it will iterate through - in
this case it is a string, "Kyle"
"Kyle"
,
as character
.print
function for each character
in
"Kyle"
successivelySo the for
loop is equivalent to:
while
loopwhile
repeats an action until a given condition is
satisfiedwhile
worksi
, that we set to 5 before running
the loopi
is greater than
0
, we tell Python to evaluate the print
function1
from
i
i
is equal to 0
, we exit the loop and
print "Blast-off"
to the consoleBeware of the infinite while
loop!
if
,
elif
, and else
<
Less than>
Greater than<=
Less than or equal to>=
Greater than or equal to==
Is equal to!=
Is not equal toTrue
and False
and
, or
, &
not