CMPT 120 Lecture : Creating Functions
23 views2 pages
20 Oct 2011
School
Department
Course
Professor
meghan78 and 39786 others unlocked
29
CMPT 120 Full Course Notes
Verified Note
29 documents
Document Summary
8 is len"s return value: we can define our own functions in python, functions are defined by a def block, eg. def add_one(num): Add one to the argument and return the result. return num + 1: the code inside the def isn"t immediately executed function is created, but that"s all. When the function is called, the code in the def runs. Eg. after the function name (in def ) comes the argument list x = add_one(y) Eg. (num) when the function is called, these variables are defined with the given values. Num will be set to 9 before the function runs. Eg. print add_one(9)/2 => 5: the function exits as soon as it hits a return statement, the triple-quoted string ( ) is a docstring (documentation string) Used to describe the purpose of the function: describe the arguments, return value, calculation, etc. Used to create a tooltip in idle.
Get access
Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers