到目前为止,
我已经能够拿一封信并找到它的号码位置。例如,a == 0
但现在我想取那个数字,然后加 4。然后返回与该数字等效的字母表。
所以,
a == 0; 0 + 4 = 5;
应该返回 f
。因为它在字母表中排在第五位!
到目前为止,这是我的代码:
def convert_int(str):
a = string.lowercase.index(str)
addition = a +13
return addition;
最佳答案
使用 chr()
和 ord()
函数。
print(ord('a')) # 97
print(chr(97 + 4)) # e
print(chr(ord('f') + 2)) # h
关于python - 如何取一个数字并找到它的字母位置python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44183253/