Python Gotchas

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.

  1. Tuples are immutable.
  2. Case Matters.
  3. Integer division trucates. (__import__ future, float cast)
  4. Classes have to inherit object to be derivable from.
  5. Type of bracket plethora-rama.
  6. Unicode.
  7. List string concatenation with .join().
  8. Shallow copies of dicts (.deepcopy())
  9. Default arguments in Python (dragons).
  10. Tabs vs Spaces.
  11. == vs is.
  12. Dictionaries are unordered.
  13. Scope, particularly scope in loops.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s