CMPT 120 Lecture : Creating Functions
23 views2 pages
20 Oct 2011
School
Department
Course
Professor
![CMPT 120 Full Course Notes](https://new-docs-thumbs.oneclass.com/doc_thumbnails/list_view/2242525-class-notes-ca-sfu-cmpt-120-lecture27.jpg)
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+
$40 USD/m
Billed monthly
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers