Python ord函数中的多个字符

mic*_*zzo 3 python hex ord

编程初学者在这里.(Python 2.7)

是否有解决方法为Python的ord函数使用多个字符?

例如,我有一个十六进制字符串'\ xff\x1a',我想要十进制值,以便我可以将其与其他十六进制字符串相加.但是ord只接受一个十六进制字符串字符.

谢谢!

Mal*_*imi 6

字符串是可迭代的,因此您可以遍历字符串,使用ord并添加结果:

your_sum = sum([ord(i) for i in '\xff\x1a'])
Run Code Online (Sandbox Code Playgroud)