Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Python unicode character codes?

Is there a way to "insert" a Unicode character into a string in Python 3? For example,

>>>import unicode
>>>string = 'This is a full block: %s' % (unicode.charcode(U+2588))
>>>print(string)
This is a full block: █

Answer*

Draft saved
Draft discarded
Cancel
6
  • 3
    ... or with unichr(), if you want to create a character from a dynamic code point (doesn't seem to be the case here; I added it for completeness). Commented Nov 3, 2012 at 21:58
  • 2
    If you prefer something more readable, you can use u'This is a full block: \N{FULL BLOCK}'. Commented Nov 3, 2012 at 22:34
  • 2
    Where can I find a list of that names like FULL BLOCK? Commented Mar 23, 2016 at 9:46
  • @buhtz, en.wikipedia.org/wiki/Block_Elements lists blocks; en.wikipedia.org/wiki/Unicode_symbols -> decodeunicode.org/de/u+2580 . HTH Commented Jun 3, 2016 at 16:18
  • Is the number you put after the \u decimal, hexadecimal, octal, or what exactly? Commented Oct 24, 2019 at 3:57

lang-py

AltStyle によって変換されたページ (->オリジナル) /