CECS 174 Lecture 4: Functions
Document Summary
# a function is a piece of code with three things: A return value (optional) computed based on the parameters. # the def keyword defines a function. def absolute_value(num): Based on the name, we can surmise that it is supposed to. # calculate the absolute value of a number. # inside a def is a block like any other. # a function"s purpose is to compute an answer. # is ready, we return it, sending it back to the person who wanted. # the answer. if num < 0: return -num. # a return statement causes the function to terminate. # that would normally follow the statement is skipped, and we go. # back to the line of code that called the function. else: return num. # the actual value given to a function to use as a parameter is called. # an argument. (we have learned this before. )