1/52
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
function definition
does not result in a value unless you call it
parametrized function definition
you can subsitute input arguments, follow the same steps and get different, but intentional, results
anatomy of a function signature
define, function name,parameters list, return type , ends with :
function signature written out
def name_of_function (parameter:type) -> returnType:
anatomy of a function definition
define,function name,parameter list, return type, function body (docstring,return statement)
function definition written out
def name_of_function (parameter:type -> returnType
“““Docstring description of the function.”””
return expression_of_type_returnType
Indentation rules
each statement in the body is indented by at least 1 level
return statements
written inside of function definitions, “stop following this function here and send my caller the results”
anatomy of a function call
name_of_function(argument=value)
argument list
a list of the input values for the parameters
what are expressions
intent to do something
what does an expression evaluate to
to a typed value at runtime
**
exponentation
*
multiplication
/
division
//
integer division
%
Remainder (modulo)
+
addition
-
subtraction
negation
-
Order of operations in python
P ()
E **
MD */%
AS +-
Addition numerical values rule
add the values together
addition string rules
concatenate them
addition concatination example
“comp”+”110”=”comp110”
addition result types (float)
float +float= float
int+float=float
addition result type (int)
int+int=int
addition result type (str)
str+str=str
what happens when you try to add incompaible types
you get an error
subtractions is meant strictly for…
numerical values
subtraction result type (float)
float-float=flolat
float-int=float
int-float=float
subtraction result type (int)
int-int=int
multiplation numerical rules
if numerical objects multiply the values
multiplation string and int rules
if string and int, repeat the strings int number of times
multiplication string and int example
“Hello”*3=”HelloHelloHello”
multiplication result type (float)
float*float=float
float*int=float
int*float=float
multiplication result type (int)
int*int=int
multiplication result type (str)
str*int=str
Division numerical rules
meant strictly for numerical values
Division rule (important)
division always results in a float
division result type
EVERY TYPE RESULTS IN FLOAT
integer division result type (int)
int // int=int
integer division result type (float)
float // float=float
float//int=float
int//float=float
Remainder “modulo” numerical type
calculates the remainder when you divide 2 numbers
remainder result type (int)
int %int =int
remainder result type (float)
float%float=float
int%float=float
float%int=float
remainder even rules
if x is even, x%2 = 0
remainder odd rules
if x is odd, x%2 is 1
exponential numerical types
raise the first power to the second
exponent result type float (float)
float**float=float
float**int=float
int**float=float
exponent result type (int)
int**int=int
relational operators
always result in a true of false value
==,≠
commonly used in programing to reperesent not, can be used for all primitive types weve learned
>,>=,<,<=
can only be used on floats and ints