A look at some quirky behaviors in Python string literals. Raw string literals (r-prefix) can't end in a backslash due to how they're lexed, even though backslashes aren't treated as escape characters. F-strings have their own oddities: the expression inside curly braces is parsed by a full Python parser, allowing nested quotes, multiline expressions, and even comments. This means lambda and walrus operator expressions must be parenthesized inside f-strings to avoid being terminated by the colon or equals sign.
83 Impressions