Assigning a function to a variable

You simply don’t call the function.

>>> def x():
>>>     print(20)
>>> y = x
>>> y()
20

The brackets tell Python that you are calling the function, so when you put them there, it calls the function and assigns y the value returned by x (which in this case is None).

Leave a Comment