88.5k views
0 votes
Assume that x is a string variable has been given a value. Write an expression whose value is true if and only if x is an hexadecimal (Base 16) digit (0-9 plus A-F or a-f).

User Diones
by
3.1k points

1 Answer

6 votes

Answer:

import string

all(c in string.hexdigits for c in s)

Step-by-step explanation:

The hexadecimal number system, often abbreviated as "hex", is a numeral system which consist of 16 symbols (base 16). The standard numeral system we are all use to, called decimal (base 10) and utilizes ten symbols: 0,1,2,3,4,5,6,7,8,9.

Using python programming language

import the string module

the second expression iterate through the digit in s and confirm if they all are within the rage of 0 -9 ad A -F. If yes , it returns True and else, it returns false

User Mansoor Jafar
by
3.1k points