wkm
wkm

Reputation: 39

Python 3.x and printing Unicode symbols


Hi
i'm trying to print out some unicode symbols, lets say from U+2660 to U+2667. With one there's no problem, I just write:

print('\u2660')

but when I want to print set of symbols in loop (or one, but dependent from variable), something like that doesn't work:

for i in range(2660, 2668):
    print('\u{}'.format(i))

I thought Python would execute .format function first and replace {} with number, and then look what is inside quotes and print it. It doesn't, and I don't understand why. :)
Please help,
TIA
wiktor

Upvotes: 1

Views: 173

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799310

The parsing of the Unicode escape is done at compile-time, not runtime.

for i in range(0x2660, 0x2668):
    print(chr(i))

Upvotes: 2

Related Questions