Example
Functions with Parameters
Parameters allow passing data to functions. Functions become more flexible.
Showing 1–10 of 86
Example
Parameters allow passing data to functions. Functions become more flexible.
Quiz
Free beginner quiz on Python functions: 15 questions on def, return, arguments, default values, *args, scope and docstrings. Instant answers.
Example
Functions group code for reuse. Defining functions with def keyword.
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.
Example
Docstrings describe what a function does. Good programming practice.
Challenge
…character, then add assert tests that would catch either function breaking.
Example
…keyword gives access to variables in the enclosing function.
Challenge
…mission log's f-string into format_log(t, level, msg), a function that returns the line instead of printing it, then fix the alignment of every log line with one change inside the function.
Challenge
…in one place and not the other. Turn the parsing into a function that any program can call, then let it decide on its own which lines are worth a record. parse_line() Move the parsing of one line into…
Challenge
…waypoints in a dict and find the nearest one with the same function.