[Tutor] Python-list thread: int vs. float

Steven D'Aprano steve at pearwood.info
Sat Feb 11 20:30:25 EST 2017


On Sat, Feb 11, 2017 at 09:10:04AM -0800, Alex Kleider wrote:

> What your 's' represents seems quite different to 'mine.'
> There must be something else going on.
> ???

I think there's an easy explanation for that, which is that eryksun 
probably just created a variable "s" but didn't show the code for that.

Unfortunately copying and pasting Unicode characters from email to the 
Python interpreter may not always work, as that depends on how well at 
least four software components deal with Unicode:

- the email program
- the copy/paste clipboard manager
- the console/terminal
- the Python interpreter

The second last one is particularly problematic under Windows.


When clarity is more important than brevity, the best way to insert 
Unicode characters into a string is to use the '\N{name}' form:

s = '\N{TAMIL DIGIT ONE}\N{VAI DIGIT TWO}\N{ORIYA DIGIT THREE}'

Since that's pure ASCII, you can copy and paste it easily even in the 
most poorly-configured system.


> Also of interest (at least to me) was the 'magic' you demonstrated in 
> the print function parameter list; my efforts to figure it out:
> >>>word = "Hello"
> >>>print((c for c in word))
> <generator object <genexpr> at 0xb71d125c>
> >>>print(*(c for c in word))
> H e l l o
> >>>print(*(c for c in word), sep='')
> Hello

Indeed: the leading * is just the systax for argument unpacking. If you 
have a sequence:

seq = [1, 2, 3, 4]

and unpack it:

print(*seq)

then what the print function sees is:

print(1, 2, 3, 4)


It works with any iterable, not just lists or tuples: also strings, 
generator expressions, and more.



-- 
Steve


More information about the Tutor mailing list