Mega Code Archive

 
Categories / Python Tutorial / String
 

A basic conversion specifier

% character marks the beginning of the conversion specifier.  Conversion flags, minimum field width, . (dot) followed by the precision. Conversion flags may be -, indicating left alignment;                          +, indicating that a sign                        " ", indicating that a space should precede positive numbers;                          0, indicating that the conversion should be zero-padded.    print 'Price of eggs: $%d' % 42  print 'Hexadecimal price of eggs: %x' % 42  from math import pi  print 'Pi: %f...' % pi  print 'Very inexact estimate of pi: %i' % pi  print 'Using str: %s' % 42L  print 'Using repr: %r' % 42L