3 ms·
Very useful. I’ve always thought of Python f-strings as being a language within a language, and not a terribly pythonic one.
by jl6 4y ago
Very useful. I’ve always thought of Python f-strings as being a language within a language, and not a terribly pythonic one.
- pantsforbirds 4y agoI'm rather curious about the "non pythonic" part of your comment. The % formatting to me has always felt like a compatibility thing with C and I've always found the {} format style much more pythonic. f strings seem like a logical extension/continuation of that formatting style into something that works really quite well with python in my personal experience. As an example I think each iteration of formatting is more readable and arguably more pythonic: log.info("%s is logged into service #%d" % (user_name, service_number)) log.info("{} is logged into service #{}".format(user_name, service_number)) log.info(f"{user_name} is logged into service #{service_number}")
- jl6 4y agoI guess I was thinking about examples like f"{3:0=+5}".