You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We should add support for using f-strings for formatting! It's the modern format and in fact so popular (which in this case I think is an indicator for really good & intuitive) that other languages have mimicked Python, like the C++ fmt library etc.
name = "world"
message = f"Hello {name}!"
# Big integers
big_num = 12345678901234567890
message = f"The value is {big_num}" # Beyond i64 range
# Expressions
base = 2
exp = 10
result = f"{base}^{exp} = {base**exp}" # "2^10 = 1024"
The text was updated successfully, but these errors were encountered:
I can't help but wonder if we should get rid of the current style, i.e.:
bla = "foo %d" % 123
it's just a carry-over from older Python, which in turn got it from C... but like f-strings just seem better in most ways, so let's get rid of ambiguity etc and just support a single format?
I agree. In fact, I originally implemented % formatting operator with the sole purpose of it being an internal translation target for f-strings. It never reached that far, though, so here we are stuck with just the old-fashioned solution as a result.
But support for f-strings should be pretty easy to add. And I think translating f-strings into % expressions is still a good idea, so I suggest we keep this form internally even if we remove it from the front-end language.
An additional thought: do we really need to mark f-strings with the prefix character f"..."? Can't we just sat that the new style of formatting is universally available? We still have the raw strings r"..." for the rare cases where formatting is undesirable.
We should add support for using f-strings for formatting! It's the modern format and in fact so popular (which in this case I think is an indicator for really good & intuitive) that other languages have mimicked Python, like the C++ fmt library etc.
The text was updated successfully, but these errors were encountered: