Last year, I got involved in trying to teach programming to school kids – this was via the excellent https://www.codeclub.org.uk/ enterprise. During this, I collated a series of Python “gotchas”, which I still think is worth sharing. As a friend of mine put it:
“The problem is that python is good, except where it does stupid things. Python programmers mostly trip over the stupid things fairly quickly, right themselves, and work around them forever, and forget that they are stupid.” – Aquarion
So, here is my list. If you think you have a good new one, please add in the comments.
- Tuples are immutable.
- Case Matters.
- Integer division trucates. (__import__ future, float cast)
- Classes have to inherit object to be derivable from.
- Type of bracket plethora-rama.
- List string concatenation with .join().
- Shallow copies of dicts (.deepcopy())
- Default arguments in Python (dragons).
- Tabs vs Spaces.
- == vs is.
- Dictionaries are unordered.
- Scope, particularly scope in loops.