Python basics
  • Introduction
  • Print function, strings, variables and development environment
  • Data types and operators in Python
  • Assignment 1
  • Getting user input and commenting
  • If/Elif/Else Conditions
  • Assignment 2
  • Data Structures
  • Loops
  • Assignment 3
  • Functions
  • Errors and Exceptions
  • Assignment 4
  • Object Oriented Programming
  • Manipulating files
  • Assignment 5
  • Modules
  • Installing packages
  • Scope
  • String formatting and List slicing
  • Ternary operators , *args and **kwargs
  • Guidelines for writing Pythonic Code
  • The End
Powered by GitBook
On this page
  • Python Enhancement Proposals
  • The Zen Of Python

Was this helpful?

Guidelines for writing Pythonic Code

PreviousTernary operators , *args and **kwargsNextThe End

Last updated 6 years ago

Was this helpful?

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:

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!

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.

Although pretty self-explanatory, if you're interested in understanding each line:

https://www.python.org/dev/peps/pep-0008/
https://medium.com/@Pythonidaer/a-brief-analysis-of-the-zen-of-python-2bfd3b76edbf