A triple-quoted string has three quotation marks and looks like this:
TRIPLE = """first\nsecond
whereas a raw string has a preceding letter r and looks like this:
RAWSTRING = r"I want some \nicely\ formatted text"
The triple-quoted string preserves everything in it, including newline characters, and it interprets the backslashes as "escaped" characters like in regular strings. It will include anything but another triple quote, which it interprets as the end. If you printed TRIPLE it would look like this:
Raw strings work a little differently. A raw string won't let you break the string over a line in the middle, and it doesn't interpret escaped characters. It will not convert the "\n" to a newline like ordinary strings or triple-quoted strings will. So if you printed RAWSTRING you would see this:
I want some \nicely\ formatted text
Triple-quoting is very convenient for copying data from somewhere and pasting it into a string when you want to preserve the newlines. Raw srtings are useful for code-related things that may contain backslashes for other reasons, such as regular expressions.
I can use a triple-quoted string to pull the list of users directly from an email and stick it into a string in a Python script, and then I can use a raw string to create a regular expression to pull the usernames out:
DATA = """Holly Martins (HMARTINS)
Anna Schmidt (ASCHMIDT)
Harry Lime (HLIME)"""
REGEX = r"\s\((\w+)\)"
names = re.findall(REGEX,DATA)
for name in names: