Basic Customization : To string : Class PYTHON TUTORIALS


PYTHON TUTORIALS » Class » To string »

 

Basic Customization


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__



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Class
» To string