CISC 121 Lecture 8: Functions, local variables, scope of variables, comments
CISC 121 verified notes
8/38View all
Document Summary
Only the first encountered will be executed. return true def first_is_shorter(thing1, thing2): if len(thing1) < len(thing2): else: print (first_is_shorter( richard","linley")) return false. Note: the previous example could have been written in a simpler manner def first_is_shorter(thing1, thing2): return len(thing1) < len(thing2) print(first_is_shorter( richard","linley")) Here"s an example wherein a list comprised of the four arguments passed in is returned def make_list(a, b, c, d): return [a, b, c, d] A variable of type bool, str, tuple, int, or float passed to a function as an argument can"t be changed in value by the function. This is because the function works internally with copies of the arguments, and these occupy their own spaces in the memory. Furthermore, a function releases the memory used for its copies of the arguments once the execution is complete. To distinguish between arguments and copies being used in functions, we refer to copies as parameters. Note: honestly, arguments" and parameters" are usually used interchangeably.