Python gotcha of the day
Thomas Jollans
tjol at tjol.eu
Thu Mar 15 05:21:24 EDT 2018
On 2018-03-15 07:11, Ben Finney wrote:
> Steven D'Aprano <steve+comp.lang.python at pearwood.info> writes:
>
>> py> """\""""""
>> '"'
>
> That's an empty string delimited by ‘"’; followed by a double-quote
> character, escaped, delimited by ‘"’; followed by two more empty
> strings. They concatenate to a single one-character string.
>
> Equivalent to
>
> "" + "\"" + "" + ""
>
> without the ‘+’ operations.
>
>> If nobody gets the answer, I shall reveal all later.
>
> My interpretation may not be how the language defines it; but it does
> match the result!
>
Then riddle me this:
if """\"""""" is equivalent to "" + "\"" + "" + "", then why isn't
""" \""" """ equivalent to "" + " \"" + " " + ""?
As I said earlier: I initially thought the way you're thinking, but got
stuck at that question and had to back-track my reasoning :-)
T
More information about the Python-list
mailing list