Variadische Funktoren in Python
input-Argumente
Bisher hatten wir die Funktion »input« immer ohne ein Argument aufgerufen. Es ist jedoch auch möglich, jene Funktion mit einem Argument aufzurufen!
Ein etwaiges Argument der Funktion »input« wird als Abfragetext („Eingabeaufforderung“) ausgegeben, bevor auf eine Eingabe gewartet wird. Hierbei handelt es sich um eine von der Auswertung bewirkte Änderung.
- Auswertung
print( input( 'Text? ' ))
Text? abc
abc
Oben ist die Ausgabe von »Text? « eine von der Auswertung von »input( 'Text? ' )« bewirkte Änderung , der Wert ist hingegen »abc«.
- Auswertung
print( '['+ input( 'Text? ' )+ ']' )
Text? abc
[abc]
Ein aufrufbares Objekt, das mit unterschiedlicher Anzahl von Argumenten aufgerufen werden kann (hier: null oder eins) wird auch als variadisch bezeichnet.
print-Aufrufe ohne Argumente
Auch die Funktion ›print‹ ist variadisch und erlaubt den Aufruf mit verschiedenen Anzahlen von Argumenten.
Bei einem print-Aufruf ohne Argumente wird lediglich ein Zeilenende ausgegeben.
- Protokoll
print()
- (Leerzeile)
Zeilenenden ⃗
Falls ein Zeilenende „↵“ ausgegeben werden soll, so kann dies im als Argument verwendeten Zeichenfolgenliteral durch das Zeichenpaar »\n« dargestellt werden.
- Auswertung
print( input( 'Ein- und Ausgabe\n================\n\nText? ' ))
Ein- und Ausgabe
================
Text? abcabc
Das interaktive Hilfesystem ⃗
Das interaktive Erklärungssystem kann durch den Aufruf »help()« gestartet werden. Es erlaubt dann die Eingabe weiterer Kommandos. Die Kommunikation basiert allerdings auf der englischen Sprache.
- Protokoll
help()
Welcome to Python 3.6's help utility!
If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/3.6/tutorial/.
Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules. To quit this help utility and
return to the interpreter, just type "quit".
To get a list of available modules, keywords, symbols, or topics, type
"modules", "keywords", "symbols", or "topics". Each module also comes
with a one-line summary of what it does; to list the modules whose name
or summary contain a given string such as "spam", type "modules spam".
Durch Eingabe von »quit« kann das interaktive Hilfesystem wieder verlassen werden.
- Protokoll
quit
You are now leaving help and returning to the Python interpreter.
If you want to ask for help on a particular object directly from the
interpreter, you can type "help(object)". Executing "help('string')"
has the same effect as typing a particular string at the help> prompt.
Die Eingabe »help« ⃗
Bei Eingabe von »help« ohne folgende Klammern, erscheint lediglich ein kurzer Hinweis zur Verwendung des Hilfesystems.
- Protokoll
help
Type help() for interactive help, or help(object) for help about object.
Ein Argument, das auch entfallen kann, bezeichnen wir als ein optionales Argument.