diff --git a/concepts/functions/introduction.md b/concepts/functions/introduction.md index a6db0ad25d9..d698253551a 100644 --- a/concepts/functions/introduction.md +++ b/concepts/functions/introduction.md @@ -5,13 +5,13 @@ Functions are used to perform specific and repetitive tasks. More formally: a function is any Python object to which the [`function call`][calls] operation can be applied. A function may be used to [`return`][return] one or more values as a result of some operation(s), or it may be used for one or more [`side effects`][side effects]. -If a function does not specify a return value it will still return `None`. +If a function does not specify a return value it will still return `None`. Following is an example of a function with a side effect: ```python >>> def hello(): -... print("Hello") +... print("Hello") ... >>> hello() Hello @@ -28,7 +28,7 @@ The argument is used by the `print` function to know what to print. Note that the body of the function is indented. The indentation is important because Python relies on it to know where that block of code ends. The function body ends at either the end of the program or just before the next line of code that is _not_ indented. -Since `hello()` does not specify a `return` value, it executes its side effect - which is calling `print()` -- and then returns `None`. +Since `hello()` does not specify a `return` value, it executes its side effect - which is calling `print()` - and then returns `None`. Finally, we call the function by using its name and the parentheses - which signals to the Python interpreter that this is a _callable_ name. Following is an example of a function with a return value: @@ -61,7 +61,7 @@ Following is an example of a function which accepts an argument: >>> def hello(name): ... return f"Hello, {name}" ... ->>>print(hello("Bob")) +>>> print(hello("Bob")) Hello, Bob ``` @@ -81,6 +81,8 @@ Traceback (most recent call last): print(hello()) TypeError: hello() missing 1 required positional argument: 'name' +``` + If we don't want the program to error with no argument (_but want to allow the calling code to not supply one_), we can define a [default argument][default arguments]. A default argument defines what value to use if the argument is missing when the function is called. @@ -103,7 +105,8 @@ For more about function arguments, please see the [function arguments][function [arguments]: https://www.w3schools.com/python/gloss_python_function_arguments.asp [calls]: https://docs.python.org/3/reference/expressions.html#calls [def]: https://www.geeksforgeeks.org/python-def-keyword/ -[function arguments]: ../function-arguments/about.md +[default arguments]: https://www.geeksforgeeks.org/default-arguments-in-python/ +[function arguments]: https://exercism.org/tracks/python/concepts/function-arguments [function]: https://docs.python.org/3/glossary.html#term-function [parameters]: https://www.codecademy.com/learn/flask-introduction-to-python/modules/learn-python3-functions/cheatsheet [return]: https://www.geeksforgeeks.org/python-return-statement/