Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Python by (12.7k 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

Output:

63

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 (26.4k points)

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

>>> import codecs

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

b'63'

There are also several ways of doing this:

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

'0x63'

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

'63'

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

'63'

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.7k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.1k users

Browse Categories

...