Using Comparison Operators for Hex Values

一笑奈何 提交于 2019-12-13 16:44:25

问题


I want to create a function that performs a certain task only when a hex value indicates an upper or lower case letter, i.e., when the hex code is between 20 and 7A. Is there a way to make a statement in python that is logically equivalent to:

if a >= 20 and a <= 7A: perform stuff

? Do I just throw a 0x in front of it and magic happens?


回答1:


yes ... you just throw a 0x and it becomes numeric ....

or int("7A",16) == 0x7A

0x20 <= a <= 0x7A you can also chain comparison operators like this (which translates roughly to "is a between val1 and val2")



来源:https://stackoverflow.com/questions/13366323/using-comparison-operators-for-hex-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!