Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k 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 (16.4k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...