Illegal literal or not?
Peter Hansen
peter at engcorp.com
Sat Jan 25 14:28:48 EST 2003
Mel Wilson wrote:
>
> In article <_RfY9.862$d66.98244 at newsread1.prod.itd.earthlink.net>,
> "LJ & MT Lareau" <ljlmtlvt at earthlink.net> wrote:
> >Is it possible to have Python produce the following literal output in the
> >interactive mode.
> >'"Let's try this!", they said.'
> >If so what is the Python statement. I've tried several ways
> >and can't seem to produce it. Thanks for the help.
>
> Just for weirdness' sake (there have been better answers)...
>
> print "'" + '"' + "Let's try this!" + '"' + ', they said.' + "'"
>
> print ''.join (["'", '"', "Let's try this!", '"', ', they said.', "'"])
Or even weirder:
>>> print '"'.join(["'", "Let's try this!", ", they said.'"])
'"Let's try this!", they said.'
And it uses several fewer list elements! ;-)
-Peter
More information about the Python-list
mailing list