简体   繁体   中英

formatting string in python using format

There is code:

xor = 127002634777471167503839844242873650079
print '{0:x}'.format(xor)
print format(xor, 'x')

Can anyone explain what two last strings means? How 5f8bd156f9e50e5381ab282ba2000b9f is generated from xor variable?

That's because this is the Hexa representation of your number.

You can set it to .2f (double in normal (fixed-point) notation), for example:

xor = 127002634777471167503839844242873650079
print '{0:.2f}'.format(xor)
print format(xor, '.2f')

Or using .2g (double in either normal or exponential notation, This type differs slightly from fixed-point notation in that insignificant zeroes to the right)

print '{0:.2g}'.format(xor)

You can read more about the type field ( .2f and .3g ) in here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM