mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-07-31 12:00:34 +02:00
added example for f-string
Literal string interpolation is new in python 3.6 [pep-0498](https://www.python.org/dev/peps/pep-0498/)
This commit is contained in:
@@ -138,6 +138,10 @@ len("This is a string") # => 16
|
|||||||
# still use the old style of formatting:
|
# still use the old style of formatting:
|
||||||
"%s can be %s the %s way" % ("Strings", "interpolated", "old") # => "Strings can be interpolated the old way"
|
"%s can be %s the %s way" % ("Strings", "interpolated", "old") # => "Strings can be interpolated the old way"
|
||||||
|
|
||||||
|
# You can also format using f-strings or formatted string literals
|
||||||
|
name = "Reiko"
|
||||||
|
f"She said her name is {name}." # => "She said her name is Reiko"
|
||||||
|
|
||||||
|
|
||||||
# None is an object
|
# None is an object
|
||||||
None # => None
|
None # => None
|
||||||
|
Reference in New Issue
Block a user