使用比较运算符来表示十六进制值 [英] Using Comparison Operators for Hex Values
问题描述
我想创建一个函数,只有当十六进制值表示大写或小写字母时,即十六进制代码在20和7A之间时,才执行某个任务。有没有一种方法可以在Python中进行逻辑上等价的语句:
如果a> = 20且a < = 7A:执行的东西
?我只是在它前面抛出一个0x并发生魔法?
是的...你只是抛出一个0x,它变成了数字....
或 int(7A,16)== 0x7A
0x20 <= a <= 0x7A
你也可以像这样链接比较运算符(大致转换为是在val1和val2之间)
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?
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")
这篇关于使用比较运算符来表示十六进制值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!