wim
wim

Reputation: 363183

use exclam (!) syntax for factorial in python

Can a working factorial function/operator be defined with a syntax like in mathematics? i.e. using the ! symbol.

I can't think of any use cases of the existing symbol where things could be ambiguous

Upvotes: 2

Views: 4448

Answers (2)

phihag
phihag

Reputation: 288150

You can not define new operators in Python. Instead, either provide a factorial function or simply use math.factorial.

Upvotes: 6

Ned Batchelder
Ned Batchelder

Reputation: 375814

If you mean, "can I define the ! operator in my Python program?," the answer is no, Python doesn't have a bang operator that can be defined.

If you mean, "could Python be extended to include a ! operator?," the answer is yes, though probably not as a postfix operator like x!. I very much doubt that the Python community would agree it was a good idea and move ahead with it though.

Upvotes: 8

Related Questions