[Tutor] sort() method and non-ASCII

boB Stepp robertvstepp at gmail.com
Mon Feb 6 07:13:13 EST 2017


On Sun, Feb 5, 2017 at 10:49 PM, Cameron Simpson <cs at zip.com.au> wrote:
> On 05Feb2017 22:27, boB Stepp <robertvstepp at gmail.com> wrote:
>>
>> On Sun, Feb 5, 2017 at 7:23 PM, Steven D'Aprano <steve at pearwood.info>
>> wrote:
>>>
>>> Alternatively, you can embed it right in the string. For code points
>>> between U+0000 and U+FFFF, use the \u escape, and for the rest, use \U
>>> escapes:
>>>
>>> py> 'pi = \u03C0'  # requires exactly four hex digits
>>> 'pi = π'
>>>
>>> py> 'pi = \U000003C0'  # requires exactly eight hex digits
>>> 'pi = π'
>>>
>>>
>>> Lastly, you can use the code point's name:
>>>
>>> py> 'pi = \N{GREEK SMALL LETTER PI}'
>>> 'pi = π'
>>
>>
>> You have surprised me here by using single quotes to enclose the
>> entire assignment statements.  I thought this would throw a syntax
>> error, but it works just like you show.  What is going on here?
>
>
> It's not an assignment statement. It's just a string. He's typing a string
> containing a \N{...} sequence and Python's printing that string back at you;
> pi's a printable character and gets displayed directly.

I just came out of the shower this morning thinking, "Stupid boB,
stupid.  That's just an escape sequence inside an overall string, not
an assignment statement."  Duh!  My brain works better asleep than
awake...

boB


More information about the Tutor mailing list