Raw strings and string literals

In order to represent something like a new line in a string, you usually use a special series of characters: \n. "\n" is an escape sequence that indicates to whatever is using the string (writing to a file, printing to the console) that there is a newline present. For example, we can see "\n" in action quite easily:

>>> print 'hello\nworld'
hello
world

There are many escape sequences of which "\n" is just one. A problem can occur when you want an actual backslash in the string, such as for file paths on Windows operating systems. We need to escape the actual backslash with another backslash so the path will be interpreted properly. The first example in the following code is not escaped, so the results are printed ...

Get Practical Maya Programming with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.