3 ms·
As demonstrated, the example above works quite well with f-strings. However, I agree with you that there are some cases where .format() is a much better solutio
by BerislavLopac 7y ago
As demonstrated, the example above works quite well with f-strings. However, I agree with you that there are some cases where .format() is a much better solution, which is when the variable values are provided dynamically. For example:
aa = [
{"foo": "baz", "bar: "bam"},
{"foo": "blah", "bar": 1234},
]
for a in aa:
print("This is my message which says {foo} and {bar}".format(**a))
- pydry 7y agoIt was demonstrated that it works quite well right up until the point where you start using quotation marks - " and/or ' in your code. Then it breaks.
- dragonwriter 7y agoActually, it works if you are using single or double quotes in your code, as long as you don't need both single and double quotes in the embedded expressions. And even that can be accommodated with f-here-strings.
- pydry 7y agoi.e. it becomes ugly and annoying to manage.
- BerislavLopac 7y ago"Ugly" is highly subjective.