Using Comparison Operators for Hex Values

comparison, hex, python

Solution

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")

Problem

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?

Original source