[Tutor] Have a very simple question

Matthew Navarre mnavarre@anteon.com
Wed, 7 Aug 2002 14:56:30 -0700


On Tuesday 06 August 2002 12:24 pm, Paul Harwood wrote:
> Why does 'doesn\'t' translate to "doesn't" ? This is in the Python
> tutorial but it doesn't say why this happens.

The backslash 'escapes' the apostrophe from ending the string. Since we u=
se=20
the same ascii character for both single quote and apostrophe python woul=
d=20
think the apostrophe was the terminating quote for the string. So the=20
backslash tells python to take the next character literally.

Another solution would be to use double quotes to delimit the string i.e.
>>>print "dosen't"
gives the same result as
>>>print 'dosen\'t'



OK,
MCN
--=20
mnavarre@anteon.com           Matthew Navarre
It was a hard sell, since he's a database person, and as far as I've seen=
,
once those database worms eat into your brain, it's hard to ever get
anything practical done again. To a database person, every nail looks
like a thumb. Or something like that. - jwz