Update index.md (#18703)

Included info about the colon being required and no closing statement, and indentation everything that is properly indented following the definition is within the scope of the function
This commit is contained in:
benpeterdalley
2018-10-14 07:54:51 +11:00
committed by Quincy Larson
parent 2154708115
commit 76f6536b4f

View File

@@ -17,6 +17,8 @@ We can create a function that writes the Fibonacci series to an arbitrary bounda
... fib(2000)
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597
The [`def`](https://docs.python.org/3/reference/compound_stmts.html#def) keyword introduces a function definition. It must be followed by the function name and the parenthesized list of formal parameters. The statements that form the body of the function start at the next line and must be indented.
The [`def`](https://docs.python.org/3/reference/compound_stmts.html#def) keyword introduces a function definition. It must be followed by the function name and the parenthesized list of formal parameters, followed by a colon. The statements that form the body of the function start at the next line and must be indented.
The first statement of the function body can optionally be a string literal; this string literal is the function's documentation string, or [docstring](https://www.python.org/dev/peps/pep-0257/) (More about docstrings can be found in the section Documentation Strings). Some tools use docstrings to automatically produce online or printed documentation or to let the user interactively browse through code. It's good practice to include docstrings in code that you write, so try to make a habit of it.
No closing statement is required for the function (eg something similar to Ruby's END), all code that is indented following the opening definition is within scope of the function.