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:
A splash of sun upon a man, tearing eyes awaken. His turning head arouses dreams from which his mind is taken. His shallow breaths uneasy queasiness the first he’s feeling. Today the day is drawing in and now the dawn is breaking.
For Rey — the one we’re speaking of — this time is cherished, for before his thoughts flood in, before his memories can fill his head with that disquieting uneasiness, he is at peace with what has passed. At least unconsciousness can serve a salve, to save his troubled thoughts until his daily life distracts. …
A butterfly sits in a cradle of leaves, floating on water supporting its weight. With a bat of its wings — its colours revealed — it lifts itself up in response to the air. The same gust of wind that has given it fright with a ripple impresses itself on the lake, a movement that carries a message that comes from a foreign, intangible place.
In the scene aforementioned is formed a whole world. Infinity bounded, alive in its shores: there’s a reason the leaves didn’t sink to the grave and the butterfly chose it to make as its nest. And components of air, when hitting the water, imparted a force that gave it new form. The question is ‘why?’ …
“We can’t get away”, they say
And I plug it in for another day
“But I need it for my evening news”
And it uses me, in its own way
I need it
“It’s like it’s always listening”
It speaks to me too, makes me happy
“My information isn’t a product”
But I produce so much and look where I am now
“Will I still be needed?” I feel
I’m being replaced somehow, by something
But it’s not faceless
No I don’t mean ‘it’
I mean the men and women using it
To slowly replace us
Taking the data we produce
Studying our every move in return for the evening news or Angry Birds or nudes
Yet every day
I plug it in
And they say we can’t get away