1
0
mirror of https://github.com/adambard/learnxinyminutes-docs.git synced 2025-08-04 22:07:52 +02:00

Merge pull request #3284 from juniorRubyist/patch-1

[python3/en] Add f-string clarification. (supported in Python 3.6 or better)
This commit is contained in:
Divay Prakash
2018-10-12 03:54:35 +05:30
committed by GitHub

View File

@@ -139,9 +139,11 @@ 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 # You can also format using f-strings or formatted string literals (in Python 3.6+)
name = "Reiko" name = "Reiko"
f"She said her name is {name}." # => "She said her name is Reiko" f"She said her name is {name}." # => "She said her name is Reiko"
# You can basically put any Python statement inside the braces and it will be output in the string.
f"{name} is {len(name)} characters long."
# None is an object # None is an object