Python Function Fun Facts

A string identifier is attached to every function at creation time

  • Which is nice for debug:
>>> dance.__name__

Functions capture local state

  • Just like JavaScript, (lexical) closure:
  • A closure remembers the values from its enclosing scope when it was created

To check whether something is callable

  • Objects can be made callable, by being assigned function as value
  • So, to check whether an object is callable:
>>> callable(foo)

Benefit of functions being first class

  • We are able to abstract and pass around behaviours

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.