0 votes
1 view
in Python by (12.5k points)

Good Afternoon, I have a query,like I'm interested to taking a single character,

c = 'c' # for example

hex_val_string = char_to_hex_string(c)

print hex_val_string



Is there any predefined string library? I just want to know is there any simplest way of going about this ?

1 Answer

0 votes
by (26k points)

In python, to use the "hex" encoding, use

>>> import codecs

>>> codecs.encode(b"c", "hex")


There are also several ways of doing this:

>>> hex(ord("c"))


>>> format(ord("c"), "x")


>>> "c".encode("hex")


Wanna become a python expert? Come, join & get certified: python certification course

Related questions

0 votes
1 answer
0 votes
0 answers
0 votes
1 answer
asked Dec 10, 2020 in Python by laddulakshana (12.5k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !