Ist es empfehlen einen String formatiert werden:Python3 Druckzeichenfolge Formatierung
var = 'python 3'
print(f"This is {var}") # prints out This is python 3
oder
var = 'python 3'
print("This is", var)
oder die alte Zeichenfolge Formatierung
var = 'python 3'
print("This is %s" % var)
Auch ist print(f"{var}")
ein neues Feature Python 3,6? Ich habe SyntaxError: invalid syntax
, wenn Sie den gleichen Code in Python 3.5.3 ausführen.
Ja, [f-Strings] (https://www.python.org/dev/peps/pep-0498 /) sind neu in 3.6 – khelwood
* "ist [es] eine neue Funktion für Python 3.6?" * - [ja] (https://docs.python.org/3.6/whatsnew/3.6 .html # pep-498-formatierte Zeichenfolgenliterale. – jonrsharpe
Wenn ich es mit [Online-Compiler] (https://repl.it/languages/python3) in 3.5.2 ausführen, druckt die Ausgabe ohne einen Fehler, so dass ich verwirrt war. – Ricek