Python equivalent to the "A" or "a" output conversions in C

E

Edward C. Jones

Consider the following line in C:
printf('%a\n', x);
where x is a float or double. This outputs a hexadecimal representation
of x. Can I do this in Python?
 
A

Alexander Blinne

Consider the following line in C:
printf('%a\n', x);
where x is a float or double. This outputs a hexadecimal representation
of x. Can I do this in Python?

Don't know why there is no format character %a or %A in python, but the
conversion is done by float method hex():

a = 3.1415
print a.hex()

Greetings
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,787
Messages
2,569,630
Members
45,335
Latest member
Tommiesal

Latest Threads

Top