Skip to content

Comment on Python string literals are kinda funnyparent

Comments

If age is a number, that won’t work.

Admittedly I’m not so familiar with Python; it does work in Java. In that case, introducing a less hazardous string concatenation operator would seem more universally useful.

In Python, that less hazardous string concatenation operator is an f-string.

I’m assuming you can only use it with string literals, hence it is less universally useful.

Nope, you can put expressions in them:

f'{a} = {functionThatReturnsAButHasSideEffects()}'

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.