by agf · 12y ago · 0 comments
Python supports optional function arguments and allows default values to be
specified for any optional argument.
No, specifying a default is what causes an argument to be optional. it can lead to some confusion when specifying an expression as the default value
for an optional function argument.
Anything you specify as a default value is an expression. The problem is when the default is mutable. the bar argument is initialized to its default (i.e., an empty list)
only the first time that foo() is called
No, rather it's when the function is defined. class variables are internally handled as dictionaries
As dictionary keys, and that's still only roughly correct.In "Common Mistake #5", he uses both a lambda and array index based looping, neither of which are particularly Pythonic. A better example of where this is a problem in otherwise Pythonic code would be good.
In "Common Mistake #6" he uses a lambda in a list comprehension -- for an article of mistakes mostly made by Python beginners, this is going to make it tough to follow the example.
In "Common Mistake #7", he describes "recursive imports" where he means "circular imports".
In "Common Mistake #8" he refers repeatedly to "stdlib" where he means the Python Standard Library. Someone is going to read that and try to "import stdlib".
[Toptal blog editor]
Again, thanks for the attention to detail. We've fixed this as well.
Because it states it right near the top of the article.
3 is a really easy mistake to make for anyone (which is why the syntax was changed).
6, 7, 9 and 10 are more obscure, and where I really appreciate this article -- and they definitely can be issues for more experienced Python devs.