|
> Python is slow. Like, really slow. On average, you’ll need about 2–10 times longer to complete a task with Python than with any other language. This doesn't seem true in my experience. First off, I'm glad the author phrased it as time "you'll need ... to complete a task," because in many cases that's a more important measure than any benchmark of the code itself. Given some data and a question about the data, I can almost certainly answer the question faster in a Python REPL or notebook than in any language which needs to be compiled. Sure, it might take ten seconds instead of one to do the math, but it takes much more than nine seconds to write a complete program in a standalone editor and compile it and run the output and look at it. Second, for tasks that are I/O-heavy and not computation-heavy, the fact that Python is interpreted doesn't really matter. If you're making a request to an API that takes 300 ms to respond, it hardly matters if processing the response takes 1 ms or 10. Finally, as the author mentions, there are several compiled Python extensions like NumPy. > Python tried to transition to static scoping, but messed it up. Usually, inner scopes — for example functions within functions — would be able to see and change outer scopes. In Python, inner scopes can only see outer scopes, but not change them. This is not true: >>> def a():
... result = []
... def f(x):
... result.append(x ** 2)
... for i in range(10):
... f(i)
... return result
...
>>> a()
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
It is ever so slightly more complicated if you want to use the regular assignment operator: you need to write a "nonlocal" statement, which has been around since Python 3.0 (https://www.python.org/dev/peps/pep-3104/), released in 2008. >>> def a():
... x = 0
... def f():
... nonlocal x
... x = 1
... f()
... return x
...
>>> a()
1
|