alexmojaki / alexmojaki/futurecoder

Functions chapter

Offen
#93 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
course material
Vorherrschende Sprache
Python
Sterne
1.5k
Forks
183
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

Some things to add to the current functions chapter:

- In the page on calling functions from functions, after showing what this looks like in various debuggers, I want to show what it looks like in a traceback. An exception should be raised in the innermost function (e.g. by intentionally misspelling a name) and then explain the resulting traceback.
- Scope and local variables:
- Explain that variables defined in one function are not accessible outside that function
- If they want to access them, they should return them
- However they can access global variables from within a function
- Explain that global and local variables should have different names to avoid errors
- Explain that `return` ends the function call. Sometimes beginners want to return a list of values like this:
```python
def double_nums(nums):
for n in nums:
return n * 2
```
Explain that they must build up a list instead. Maybe hint at generators but don't actually show them.

Things that will only be covered in a later chapter:

- Variadic, named, or optional arguments/parameters
- Higher order functions, functions as objects, functional programming, etc.
- How to set global variables with the `global` statement
- Inner functions and closures

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.