Basic Customization : to string « Class « Python Tutorial






class MyRound(object):
   def __init__(self, val):
      assert isinstance(val, float), "Value must be a float!"
      self.value = round(val, 2)

   def __str__(self):
      return '%.2f' % self.value

   __repr__ = __str__








11.31.to string
11.31.1.Simple Customization
11.31.2.Basic Customization
11.31.3.Numeric Customization
11.31.4.Representation of phone number in USA format: (xxx) xxx-xxxx.