尝试打印 UTf-8 字符的位(表情符号“👍”)

问题描述 投票:0回答:1

我正在尝试打印 UTf-8 字符的位。在这种情况下是表情符号。 根据以下视频:https://www.youtube.com/watch?v=ut74oHojxqo 以下代码

script.py
(均来自使用 vim 编辑的脚本和终端中的 python 命令行

s = '👍'
print(len(s))
print(s[0])

应给出以下输出:

$ python script.py 
4
'xf0'

但是它给了我

$ python script.py 
1
👍
python string utf-8 byte bit
1个回答
0
投票

Python 3 等效项:

s = '👍'.encode()  # Encode Unicode code points to default UTF-8 encoding.
print(len(s))
print(s.hex(' '))

输出:

4
f0 9f 91 8d
© www.soinside.com 2019 - 2024. All rights reserved.