ITP 115 Lecture 9: ITP 115 Lecture 9
Document Summary
Print() input( ) returns a string int(string) returns an int str(int) returns a string len(sequence) returns # of items. Perform a task and return control to your program. Allow you to break up code into manageable, bite-size chunks. Programs w/functions can be easier to create and work with. Function definition: what it does, like recipe. Function call: actually using the function. Use the word def, followed by a function name (same rules as a variable name), followed by a pair of parentheses, followed by a colon, and then an indented block of statements def functionname (): statement(s) # define a function called spam def spam (): print( spam, spam, spam ) Calling a function: use the name of the function followed by a set of parentheses functionname (, must define the function before you call it print( spam, spam, spam ) # define a function called spam def spam (): spam() spam() Output spam, spam, spam spam, spam, spam.