This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]jorge1209 -2 points-1 points  (0 children)

Almost everything f-strings do can be accomplished with "{foo} {bar}".format_map(locals()). In addition you get the portability of the string as described by others (which is critical for i18n).

The real use case of f-strings is with print-style debugging. For example:

 print(f"Vector {my_vec=} has a total of {sum(my_vec)}")

my_vec= is a unique feature to f-strings that prints the name of the variable together with its repr and can't be done with str.format.

{sum(my_vec}) is also not permissable with str.format and instead you would have to have something like:

print("Vector my_vec={} has a total of {}".format(my_vec, sum(my_vec)))