top | item 42916177

(no title)

hikarudo | 1 year ago

Sincere question: what's wrong with Python f-strings?

discuss

order

boxed|1 year ago

Three people in a row and not one of you guys checked out Swift strings before commenting, thus making exactly the mistake I complained about.

Look up Swift strings. Python has 4 types of string literals. Swift has 1. And they are BETTER and more powerful. Cleaner.

edflsafoiewq|1 year ago

Swift has "normal strings", #"raw strings"#, and """ for multiline strings. For interpolation, it uses "The answer is \(1+2)", but in a raw string you need #"The answer is \#(1+2)"#.

So compared to Python, string interpolation is always "on" and doesn't need an f-prefix. Because it uses the string escaping syntax, it doesn't have to take over a regular character like {, which requires {{ escaping.