Created
October 19, 2015 21:53
-
-
Save thorsummoner/d09d6645b4f7fecc9c18 to your computer and use it in GitHub Desktop.
Example using the '%' (mod) operator to return percent.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numbers | |
class Percent(float): | |
def __mod__(self, other): | |
"""Override the builtin % to give X * Y / 100.0 """ | |
return self / other * 100.0 | |
if __name__ == '__main__': | |
from pprint import pprint | |
pprint( | |
Percent(5) % 60 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment