Mega Code Archive

 
Categories / Python Tutorial / Class
 

Simple Customization

class MyRound(object):     def __init__(self, val):         assert isinstance(val, float), "Value must be a float!"         self.value = round(val, 2) rfm = MyRound(42) print rfm rfm = MyRound(4.2) print rfm 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 str(self.value) rfm = MyRound(5.590464) print rfm rfm = MyRound(5.5964) print rfm 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 rfm = MyRound(5.5964) print rfm