INFO1110 Lecture Notes - Lecture 4: Order Of Merit

13 views1 pages

Document Summary

Returning from a function and printing in a function are different things! If a function does not explicitly return anything, the function will return none. def print_hello(name): print("hello, {}". format(name)) def get_hello_string(name): return "hello, {}". format(name) print("> calling print_hello") ret = print_hello("alice") print(ret) print("> calling get_hello_string") ret = get_hello_string("bob") print(ret) Here are some general things to keep in mind when writing functions: a function should do one thing, and one thing well, avoid long functions (over 50 lines) If your function is getting too long, break it up into smaller units: place returns statements near the end of your methods, avoid using global variables inside your function. Docstrings (documentation strings) are used as a comment to describe what your func- tion does.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents