MC logo
Strings II
[^] Code Examples
<<Strings I str2.py Strings Operations>>

# Strings have various escapes.
print("Hi\nth\ere,\thow \141\x72\145\x20you?")

# Raw strings ignore them.
print(r"Hi\nth\ere,\thow \141\x72\145\x20you?")


# Very useful when building file paths on Windows.  
badpath = 'C:\that\new\stuff.txt';
path = r'C:\that\new\stuff.txt';

Lutz and Ascher list the escape charaters on p. 77. The numeric and \x escapes are ASCII codes in octal and hexadecimal, respectively. If the escape is unknown, the backslash is retained, unlike C.

There is also a u qualifier to build Unicode strings.
<<Strings I Strings Operations>>