Simple syntax question
Erik Max Francis
max at alcyone.com
Sun May 11 03:04:38 EDT 2003
combe wrote:
> I'm reading the "Programming Python" bible and I often find the
> following
> syntax :
>
> MyVar = r'some strig data'
>
> I can't see what the "r" stands for.
It indicates a "raw" string literal. In raw string literals, escape
sequences aren't processed, so a backslash has no special meaning there:
>>> '\n' # this is a newline
'\n'
>>> '\\n' # this is a backslash and an n
'\\n'
>>> r'\n' # this is a backslash and an n, too
'\\n'
They're useful for when you want to build a string that contains a lot
of backslashes, such as in regular expression strings.
--
Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/ \ If love be good, from whence cometh my woe?
\__/ Chaucer
WebVal / http://www.alcyone.com/pyos/webval/
URL scanner, maintainer, and validator in Python.
More information about the Python-list
mailing list