string
module in PythonThe string
module in Python is a collection of different constants.
hexdigits
constantThe hexdigits
constant in the string module contains all the ASCII hexadecimal digits.
The constant’s value is as follows:
0123456789abcdefABCDEF
string.hexdigits
As hexdigits
is a constant, we can access it via the string
module name.
Let’s have a look at the code below:
import stringhexdigits_output = string.hexdigitsprint("string.hexdigits = '%s'" % (hexdigits_output))
string
module.string.hexdigits
in the hexdigits_output
variable.hexdigits_output
.Let’s have a look at the code below:
import stringdef is_hexdigits_only(str_input):for i in str_input:if i not in string.hexdigits:return Falsereturn Truestr_to_check_1 = "aba123fdf"print("Does %s contains only hexadecimal digits? %s" % (str_to_check_1, is_hexdigits_only(str_to_check_1)))str_to_check_2 = "abji232daosfdgfRFDFD"print("Does %s contains only hexadecimal digits? %s" % (str_to_check_2, is_hexdigits_only(str_to_check_2)))
string
module.is_hexdigits_only
that accepts a string as the parameter. It also checks whether or not the input string contains only ASCII hexadecimal digits.str_to_check_1
that contains only ASCII hexadecimal digits.is_hexdigits_only
method, and pass str_to_check_1
as a parameter.str_to_check_2
that contains lowercase and uppercase ASCII letters and digits.is_hexdigits_only
method, and pass str_to_check_2
as a parameter.