# Funktionen

Mit einer Funktion kannst du mehrere Befehle als einen Definieren, und quasi einen neuen Befehl erstellen. Ich zeige dir ein Beispiel:

```python
def testcode():
    print("Hello")
    print("World")
```

Wenn du diesen Code ausführst, passiert jedoch nichts. Das liegt daran, dass du den neu Erstellten Befehl noch gar nicht ausgeführt hast:

```python
def testcode():
    print("Hello")
    print("World")

testcode()
>>> Hello
>>> World
```

Wenn du also mehrmals einen bestimmten Code ausführen möchtest, kannst du aus vielen Befehlen einen machen, und ausführen!

Wenn du eine Variable in einer Funktion veränderst, ändert sie sich NICHT im eigentlichen Code:

```python
hallo = "Welt"
def etwas():
    hallo = "Hallo"
    print(hallo)

etwas()
>>> Hallo
print(hallo)
>>> Welt
```

Du kannst auch Funktions-Variablen Erstellen, die du dann in den Befehl als Argument einfügst:

```python
def etwas(arg1, arg2):
    #
    # arg1 und arg2 sind Variablen, du kannst
    # sie also so nennen, wie du möchtest!
    #
    # In diesem Fall:
    # arg1 = Welt
    # arg2 = Hallo
    #
    print(arg2) # Das zweite Argument wird als erstes ausgegeben (Hallo)
    print(arg1) # Erst danach wird das erste Argument ausgegeben (Welt)

etwas("Welt", "Hallo") 
>>> Hallo
>>> Welt
```

{% hint style="warning" %}
Die Funktions-Variablen können NUR in der Funktion genutzt werden!
{% endhint %}

Und das können wir jetzt nutzen:

```python
def frage(text):
    antwort = input(frage+" ") # Hier wird ebenfalls ein Leerzeichen eingefügt, damit zwischen der Frage und der Antwort Platz ist!
    print("Deine Antwort: " + antwort)

frage("Wie ist dein Name?")
>>> Wie ist dein Name? Freddy # Freddy ist in diesem Fall eingetippt
>>> Deine Antwort: Freddy
frage("Was hast du heute zum Mittagessen gegessen?")
>>> Was hast du heute zum Mittagessen gegessen? Brot # Brot ist in diesem Fall eingetippt
>>> Deine Antwort: Brot
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://python.supernova125.de/def.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
