I have always wondered why can’t we use hyphens in between function names and variable names in python
Having tried functional programming languages like Lisp and Clojure, where hyphens are allowed. Why python doesn’t do that.
# This won't work -- SyntaxError
def is-even(num):
return num % 2
# This will work
def is_even(num):
return num % 2
I am sure Sir Guido must have done this because of some reasons. I googled but couldn’t manage to find the answer. Can anyone please throw some light on this?
Because hyphen is used as the subtraction operator. Imagine that you could have an
is-evenfunction, and then you had code like this:Is
is-even(another_var)a call to the functionis-even, or is it subtracting the result of the functionevenfrom a variable namedis?Lisp dialects don’t have this problem, since they use prefix notation. For example, there’s clear difference between
and
in Lisps.