I don't have any specific knowledge about this, but it probably has not been done because it could easily cause some subtle bugs that aren't immediately obvious, and the benefits aren't that great in comparison to just using the format specification language to produce % representation.
Consider, if % was a postix operator: >>> x = 1.11 >>> xmod1 = x % # whoops - forgot second argument, and no error to warn me >>> print(f"the decimal portion of x is: {xmod1}") # no error here either the modulo value is: 111.00000000000001% yuck! Another problem is: if you want a "%" sign displayed as part of the repr, this would require a new "percent" numerical subtype with it's own __repr__. Which opens up a big can of worms: - should percent instances inter-operate with floats, ints, Decimals....? - if so, what should the return value be when you add/subtract/etc them with other types? Also consider that if this was done, it would be the only postfix operator in the entire language. If you really want to do this, you could subclass float and overload the __rmod__ and just have it take an ellipses as the RHS argument, which doesn't look too awful to me: >>> xpct = 1.11 % ... # not too bad! and errors are preserved when misused... >>> f"{xpct:.0f}" '111' >>> f"{xpct:.0f}%" '111%' But IMO there's already a much better way to do all of this: >>> f"{x:.0%}" '111%'
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/