15.04.2013 Views

Core Python Programming (2nd Edition)

Core Python Programming (2nd Edition)

Core Python Programming (2nd Edition)

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

'6c'<br />

>>><br />

>>> "%X" % 108<br />

'6C'<br />

>>><br />

>>> "%#X" % 108<br />

'0X6C'<br />

>>><br />

>>> "%#x" % 108<br />

'0x6c'<br />

Floating Point and Exponential Notation Output<br />

>>><br />

>>> '%f' % 1234.567890<br />

'1234.567890'<br />

>>><br />

>>> '%.2f' % 1234.567890<br />

'1234.57'<br />

>>><br />

>>> '%E' % 1234.567890<br />

'1.234568E+03'<br />

>>><br />

>>> '%e' % 1234.567890<br />

'1.234568e+03'<br />

>>><br />

>>> '%g' % 1234.567890<br />

'1234.57'<br />

>>><br />

>>> '%G' % 1234.567890<br />

'1234.57'<br />

>>><br />

>>> "%e" % (1111111111111111111111L)<br />

'1.111111e+21'<br />

Integer and String Output<br />

>>> "%+d" % 4<br />

'+4'<br />

>>><br />

>>> "%+d" % -4<br />

'-4'<br />

>>><br />

>>> "we are at %d%%" % 100<br />

'we are at 100%'<br />

>>><br />

>>> 'Your host is: %s' % 'earth'<br />

'Your host is: earth'<br />

>>><br />

>>> 'Host: %s\tPort: %d' % ('mars', 80)<br />

'Host: mars Port: 80'<br />

>>><br />

>>> num = 123<br />

>>> 'dec: %d/oct: %#o/hex: %#X' % (num, num, num)<br />

'dec: 123/oct: 0173/hex: 0X7B'

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!