0

Is it possible do define your own function which can be used as a non-alphabetic function sign?

I'm just curious whether it is possible.

I don't want to change some existing function like __eq__ or __gt__.

For example '***' sign would do this computation on Int: x***x = x^2^2. So I would define this function and then I could use it this way:

for x in xrange(3):
    print x***x

- 0
- 1
- 16
- 81
Milano
  • 18,048
  • 37
  • 153
  • 353
  • See also http://stackoverflow.com/q/214881/3001761 – jonrsharpe Jan 14 '16 at 22:35
  • 2
    Any valid identifier can be an infix operator with [this clever hack](http://tomerfiliba.com/blog/Infix-Operators/) - however, IIRC, `***` is not a valid identifier name, so some of the more esoteric operators cannot be created. No `<<+|` - both fortunately and unfortunately. – Sean Vieira Jan 14 '16 at 22:36
  • 1
    This might be helpful to know which identifiers are allowed: https://docs.python.org/3.2/reference/lexical_analysis.html#identifiers. In Python 2, however, only alphabetical characters, numbers, and underscores are allowed. – frogbandit Jan 14 '16 at 22:36

0 Answers0