Mega Code Archive

 
Categories / Python Tutorial / Class
 

Deriving Standard Types

class RoundFloat( float):     def __new__(cls, val):         return super(RoundFloat, cls).__new__(cls, round(val, 2)) print RoundFloat(1.5955) print RoundFloat(1.5945) print RoundFloat(-1.9955)