Is there a difference between capital and lowercase string prefixes?

There's no difference in meaning between these notations. Reference:

Both string and bytes literals may optionally be prefixed with a letter 'r' or 'R'; such strings are called raw strings and treat backslashes as literal characters

The same goes for other prefixes.


Now regarding VSCode behaviour:

  • the first coloring (with yellow {2}) happens when the editor assumes you're writing a regular expression,
  • the second one (with blue {2}) happens when the editor thinks you're writing a format string, something like "{0}, {1}!".format("Hello", "world").

This becomes more obvious when we add some more syntax:

highlighted code snippet

Now, looks like VSCode should treat R"literal" the same as r"literal", but instead it colors it the same as "literal", which is probably a tiny bug that nobody spotted because everyone writes lowercase r.

Correction from comment: It's not a bug, it's a feature! VSCode's highlighter makes clever use of the fact that r and R prefixes are equivalent, and allows you, the developer, to have correct coloring by adopting a convention of using r for regex raw strings and R for non-regex raw strings.

Raw strings are often interpreted as regular expressions. This is a bit of a problem, because depending on the application this may actually not be the most common case. (...) MagicPython follows a convention that a lower-case r prefix means a regexp string, but an upper-case R prefix means just a raw string with no special regexp semantics.


In general, Python is case sensitive. Per the string literal syntax specification, however, string prefixes can be either case (or order). So the difference is visual, although tradition is mostly to use lower case, and upper case letters can be harder to distinguish.