Python
Python is an interpreted, general-purpose, high-level programming language. Some properties of Python include:
- whitespaces being significant
- dynamically-typed
- garbage-collected
Python Import Resolution
Say you have a Python import statement:
import abc
Python will look up the following in order:
- sys.modules: this is the cache containing previously imported modules
- built-in modules
- sys.path: Usually includes the current directory
Python Default Parameter Values
Python has interesting behaviour for default values:
def a(v=[]):
v.append(1)
print(v)
a()
a()
a()
a()
Why does this happen? Default parameter values are always evaluated when, and only when, the “def” statement they belong to is executed. Also note that “def” is an executable statement in Python, and that default arguments are evaluated in the “def” statement’s environment. If you execute “def” multiple times, it’ll create a new function object (with freshly calculated default values) each time.