CMPT 120 Chapter 3: Think Python Readings Part 14
39 views2 pages
29 Aug 2018
School
Department
Course
Professor
meghan78 and 39786 others unlocked
29
CMPT 120 Full Course Notes
Verified Note
29 documents
Document Summary
Some of the functions we have seen require arguments. For example, when you call math. sin you pass a number as an argument. Some functions take more than one argument: math. pow takes two, the base and the exponent. Inside the function, the arguments are assigned to variables called parameters. Here is a definition for a function that takes an argument: This function assigns the argument to a parameter named bruce. When the function is called, it prints the value of the parameter (whatever it is) twice. This function works with any value that can be printed. The same rules of composition that apply to built-in functions also apply to programmer- defined functions, so we can use any kind of expression as an argument for print_twice: The argument is evaluated before the function is called, so in the examples the expressions "spam "*4 and math. cos(math. pi) are only evaluated once. You can also use a variable as an argument: