Call a function with a single character in Python
<p>If I have a function that computes the factorial of a number, is there any way that this function can be called with the character '!' ?</p>

<p>Essentially, I would like to type</p>

<pre><code>In [1]: 5!
</code></pre>

<p>and receive:</p>

<pre><code>120
</code></pre>

<p>I am using Python 3.5 with the Spyder IDE.</p>

<p>You can try something like this:</p>

<pre><code>from math import factorial

input_string = "5!"

def is_int(input_string):
 try:
  int(input_string[:-1])
  return True
 except ValueError:
  return False

if input_string[-1] == "!" and is_int(input_string):
 print(factorial(int(input_string[:-1])))
</code></pre>

<p>This is not exactly you want but it looks like closest solution
This code formatted for python 2.7</p>

python function spyder