What exactly do "u" and "r" string prefixes do, and what are raw string literals?

In Python, the "r" prefix before a string denotes that it is a raw string literal. This means that any backslashes () in the string are not treated as escape characters. For example, the string "C:\Windows" would normally be interpreted as the string "C:Windows", but with the "r" prefix, it is interpreted as the string "C:\Windows".

normal_string = "C:\Windows"
print(normal_string)  # Output: C:Windows

raw_string = r"C:\Windows"
print(raw_string)  # Output: C:\Windows

Watch a course Python - The Practical Guide

The "u" prefix before a string denotes that it is a Unicode string literal. Unicode is a standard for encoding characters in a way that can be understood by computers. In Python 3, all strings are Unicode by default, so the "u" prefix is not necessary.

unicode_string = u"Hello, 世界!"

You can also combine prefixes like ur to make a raw unicode string. But this is not very common in python 3 as all string are unicode by default

raw_unicode_string = ur"C:\Windows"