Example
Documenting Functions
Docstrings describe what a function does. Good programming practice.
Showing 11–20 of 79
Example
Docstrings describe what a function does. Good programming practice.
Example
Functions group code for reuse. Defining functions with def keyword.
Quiz
Free beginner quiz on Python functions: 15 questions on def, return, arguments, default values, *args, scope and docstrings. Instant answers.
Example
Parameters allow passing data to functions. Functions become more flexible.
Challenge
…statuses give None, make every path return, then write a function where every path returns.
Challenge
…Read it from the bottom up to find the error, the function and the line, fix the bug there, then follow a longer traceback through four calls to a second bug.
Article Python Fundamentals
Learn to write your own Python functions, from your first def to return values, default parameters and scope, with runnable examples, common mistakes and six practice projects.
Challenge
…character, then add assert tests that would catch either function breaking.
Example
…keyword gives access to variables in the enclosing function.
Example
Return statement returns a value from function. Function can perform calculations and give result.