Deriving Standard Types : Subclass : Class PYTHON TUTORIALS


PYTHON TUTORIALS » Class » Subclass »

 

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)



Leave a Comment / Note


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


PYTHON TUTORIALS

 Navioo Class
» Subclass