Why does python disallow usage of hyphens within function and variable names?

Because hyphen is used as the subtraction operator. Imagine that you could have an is-even function, and then you had code like this:

my_var = is-even(another_var)

Is is-even(another_var) a call to the function is-even, or is it subtracting the result of the function even from a variable named is?

Lisp dialects don’t have this problem, since they use prefix notation. For example, there’s clear difference between

(is-even 4)

and

(- is (even 4))

in Lisps.

Leave a Comment