Guidelines for writing Pythonic Code

Hey there! Welcome back to the Python basics tutorial! Now you're finally done with the basics. I'll tell you about some guidelines today to help you write clean, readable code or "Pythonic code".

Python Enhancement Proposals

"Python Enhancement Proposal"s or "PEP"s are guidelines for writing Pythonic code. The most common one is PEP8. Since it's simply too big to fit in here, I'll leave you with a link: https://www.python.org/dev/peps/pep-0008/

The Zen Of Python

The Zen Of Python is a short poem written by Tim Peters. You can find it by importing the this module.

>>> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

Although pretty self-explanatory, if you're interested in understanding each line: https://medium.com/@Pythonidaer/a-brief-analysis-of-the-zen-of-python-2bfd3b76edbf

If you follow these basic rules, you'll be writing Pythonic code in no time.

Alright. This is the end of the journey. You've learned the Python basics. Now, before I officially end this tutorial, I just wanna give you one piece of advice:

Practice makes perfect.

Last updated