简体   繁体   中英

Python unicode character codes?

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

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

是的, unicode字符转义

print u'This is a full block: \u2588'

You can use \? where you replace dddd with the the charcode.

print u"Foo\u0020bar"

Prints

Foo bar

You can use \\u to escape a Unicode character code:

s = u'\u0020'

which defines a string containing the space character.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM