<div class="gmail_quote">On Sat, Jun 4, 2011 at 10:30, Hendrik Boom <span dir="ltr"><<a href="mailto:hendrik@topoi.pooq.com">hendrik@topoi.pooq.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
On Fri, Jun 03, 2011 at 11:40:37PM -0400, Eli Barzilay wrote:<br>
><br>
> >>> print "\"<br>
> [SyntaxError: ...] <-- surprise<br>
<br>
Just curious: what happens with<br>
<br>
>>> print "\""<br><br></blockquote><div><div>>>> "\""</div><div>'"'</div></div><div><br></div><div><br></div><div>The internal double quote is escaped by the backslash.</div>
<div>The result is just another way to write the same without need to escape:</div><div><br></div><div>'"' </div></div><br><div>(single, double, single quote)</div><div><br></div><div><br></div><div>And if you "print" it, you get:</div>
<div><br></div><div><div>>>> print "\""</div><div>"</div></div><div><br></div><div><br></div><div>If I am not wrong, it is the same as Racket, except for the representation that the prompt spits out for "\" " .</div>
<div>Although Python's motto is "<a href="http://www.python.org/dev/peps/pep-0020/">There should be one-- and preferably only one --obvious way to do it.</a>", the language itself does one thing in two different ways, there are actually more than 2 ways to represent that string.</div>
<div><br></div><div>You see some more "inconsistency" if you try to represent a single quote as string:</div><div><br></div><div><div>>>> "'"</div><div>"'"</div></div><div><br>
</div><div>This time the internal representation of the string uses " instead of '.</div><div><br></div><div><br></div><div>[]'s</div><div><br></div><div>Rodolfo Carvalho</div>