CS 110 Lecture Notes - Lecture 6: Global Variable, Docstring

74 views2 pages
15 Sep 2016
Course
Professor

Document Summary

Procedure follows steps, doesn"t return a value. Python and other c-based languages do not have procedures, they always return something. When there is a function that doesn"t have a return value at the end, python automatically returns an object none. Example: def noreturn(): x = 5 y = 6 def main(): noreturn() main() This will return none, because the function has no set return value. When there is a return value, anything that comes after the return call is ignored. This is different from other languages like java, which throw an actual error when there is a return value before other lines of code in the function. Example: def extravalue(): x = 5 return x x = 2 def main(): print(extravalue()) main() This will print out 5, because that is the value of x returned. x = 2 is ignored entirely. At the beginning of every function, you have to create a docstring for it.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents

Related Questions