How to change string into hex in python? Hex is a hexadecimal number. The following is an introduction to various type conversions (int, str, chr, hex, oct, etc.) in python:
int(x [,base ] ) Convert Convert x to a floating point number
complex(real [,imag ]) Create a complex number
str(x) Convert object x to a string
repr(x) Convert object x to expression string
eval(str ) Used to evaluate a valid Python expression in a string and return an object
tuple(s) Convert the sequence s into a tuple
list (S) Convert the sequence s with a list
# chr (x) to convert an integer to a character
## unichr (x) to convert an integer to unicode character
# ord(x ) ‐ Convert a character to its integer value ’’’’’’ out out through out''''''' ’ ’ ’’’’’’’’’’' ’ ’''''''''’’''''''‐‐' Convert's''''‐'''' through through''''''‐‐‐‐‐‐ involved in. to to d(x to) . ) Convert an integer to An octal string Related recommendations: "Python Video Tutorial
"Convert a hexadecimal string to a decimal number:>>> print int('ff', 16) 255
To convert decimal numbers into hexadecimal strings, you can call the built-in hex() function:
>>> print hex(255) 0xff
>>> print binascii.b2a_hex('A') 41
>>>print binascii.a2b_hex('41') “A”
The above is the detailed content of How to convert string into hex in python. For more information, please follow other related articles on the PHP Chinese website!