Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Comparison Operators for Hex Values

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?

like image 908
user1427661 Avatar asked Dec 20 '22 13:12

user1427661


1 Answers

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

like image 120
Joran Beasley Avatar answered Jan 02 '23 00:01

Joran Beasley