Python string literals are kinda funny

Python’s weird quote rules just started a full-on comment section civil war

TLDR: Python’s string rules turned heads because a “raw” string still breaks in one oddly specific case, while f-strings allow surprisingly wild behavior. In the comments, people split hard between loving the convenience and complaining that Python’s newer features are just confusing punctuation chaos.

A tiny post about how Python reads text somehow turned into a deliciously nerdy meltdown. The original gag was simple: in Python, a so-called “raw” string still has one hilariously awkward rule — it can’t end with a backslash. Then things got even messier with f-strings, the newer format that lets you drop values into text, because they follow a whole different set of rules and can do bizarre-looking tricks like producing a lone } from what looks like punctuation soup. For regular people: yes, the language is being weird about quote marks and slashes, and yes, developers are absolutely arguing about it.

That’s where the comments stole the show. One reader basically did a double take — “Huh?” — because the example seemed to clash with the quote rules they thought they knew. Another went full practical-mode and said when building JSON, they retreat to old-school %s formatting because it’s just cleaner and less annoying. Then came the real drama: one commenter declared they’re not a fan of f-strings at all, saying loads of newer Python features have only made the language more complicated with little payoff. Ouch.

But not everyone grabbed a pitchfork. One veteran proudly admitted they ignore all the “funky strings” and just glue text together the old-fashioned way, while another shrugged off the chaos and said, edge cases aside, f-strings are great. So the vibe is clear: half the crowd is laughing at Python’s ridiculous quote gymnastics, and the other half is debating whether modern convenience features are genius or just extra homework with punctuation.

Key Points

  • The article states that `r'asdf\'` is a syntax error in Python, while `r'asdf\''` is valid and produces the string `asdf\'`.
  • Raw string literals in Python do not process escape sequences normally, but they are still lexed using regular string literal rules.
  • Because of Python's lexing behavior, a raw string literal cannot end with a backslash.
  • The article says f-string expressions are parsed by a full Python parser, allowing quotes, multiline expressions, and comments inside `{...}`.
  • In f-strings, expressions terminate at an unparenthesized and uncommented `}`, `!`, or `:`, which affects constructs such as lambda and assignment expressions.

Hottest takes

"I feel like 90% of new Python features in the last 10 years just increased language complexity without any benefit." — dwdz
"Been using python for almost 10 years. I never use any of the funky strings." — TZubiri
"Whenever I'm building a JSON document, I revert to the old %s syntax" — smitty1e
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.