Are you taking advantage of these features of Python that can help make your code make more sense?

Code readability is not just about making your code shorter. It is about reducing the intellectual burden of understanding what your code is doing and how it is doing it.

Some general rules of thumb are: explicit is better than implicit, clear is better than short, and don’t repeat yourself (DRY).

With that in mind, here are three (plus one bonus!) examples of situations where avoiding an if statement can help make your code more readable. They are:

  1. Testing for equality with more than one possible…


Jonny Jackson

PhD student in Artificial Intelligence and Medicine. Teacher of coding and machine learning to children and adults alike.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store