1
0
mirror of https://github.com/adambard/learnxinyminutes-docs.git synced 2025-08-01 04:20:39 +02:00

Added example for f-strings

This commit is contained in:
caminsha
2020-02-17 00:26:43 +01:00
parent 254a609876
commit c5362aaed1

View File

@@ -116,6 +116,14 @@ False or True #=> True
"{0} mag Spagetthi, {0} liebt es zu Schwimmen und ganz besonders mag {0} {1}".format("Hans", "Blattsalat")
#=> "Hans mag Spagetthi, Hans liebt es zu Schwimmen und ganz besonders mag Hans Blattsalat"
# Die Formatierung kann auch mit `f-strings` oder formattierten Strings gemacht
# werden (ab Python 3.6+)
name = "Sandra"
f"Sie hat gesagt, ihr name sei {name}." # => Sie hat gesagt, ihr Name sei Sandra."
# Es ist möglich, andere Anweisungen innerhalb der geschweiften Klammern zu
# setzen, welche dann im Output des Strings angezeigt werden.
f"{name} ist {len(name)} Zeichen lang" # => Sandra ist 6 Zeichen lang.
# None ist ein Objekt
None #=> None