function
domain (set of allowable inputs)
codomain (set of all possible outputs
rule: ties each input to an outt
ties every element of the domain to some element
in the range
(consistent)
len is a mathematical function
domain : sequences
codomain: integers
def f(x):
return x*x
def greet():
print("Hello!")
no input
no output
has a side-effect: it puts "hello" to the screen
def add_em(x,y): (domain: two-tuples of numbers)
return x + y
def foo(x):
print(x)
return x + 5
Mathematical functions have no side-effects.
CS people say "pure function" for math functions.
functions ahve
preconditions:
something that is true prior to call
number and types of arguments.
postcondition:
returned object
side-effect
Truthiness
An object is truth if it can be cast to a bool and
come out True.
An object is falsy if it can be cast to a bool and
come out False.
if
elif
else
while: "sticky if"