打印单词中所有字母的unicode

时间:2019-01-07 22:42:08

标签: python python-unicode

我陷入了这个问题:

  

用户输入一个单词,程序输出单词中每个字母的unicode

这是输入语句的外观:

word = input("Enter a word: ")

假设用户输入单词“ Cat”,则输出将如下所示:

C: 67
a: 97
t: 116

2 个答案:

答案 0 :(得分:0)

使用ord()

word = input("Enter a word: ")
for letter in word:
    print(letter + ': ', ord(letter))

答案 1 :(得分:0)

根据您的示例,我想您尝试输出的是字符的ASCII值。如果是这样,您可以使用python内置函数ord()检查ASCII值。

find(...).fetch()

输出:

userInput = input("Enter a word: ")

for i in userInput:
    print('{}: {}'.format(i, ord(i)))