Dec-22-2020, 06:38 PM
What do you mean by "get hex value is: FF"? Python lets you use hex notation when writing a string literal.
x = 0xffAnd you can print an integer using hex notation a number of ways.
print(hex(x)) print(f'{x:x}') print(f'{x:X}')Or do you want to "get" a hex value, as in using input() to enter a hex value? Unfortunately I get an error when I try to do this:
x = int(input('Enter a number in hex format '))Then error is informative "ValueError: invalid literal for int() with base 10: '0xFF'. So I tried this:
x = int(input('Enter a number in hex format '), 16)This works if I enter 'ff', 'FF', '0xff' or '0xFF'