What is the meaning of different aphorism in zen of python

what is the meaning of zen of python

The Zen of Python is a collection of 20 software principles that influences the design of Python Programming Language.

Zen Of Python:

Zen of Python is written as an informational entry number 20 in Python Enhancement Proposals (PEP). This is also included as easter egg in python interpreter which can be invoked by typing import this .

zen of python import this Easter egg

 

Explaination:
  • Beautiful is better than ugly.
    Code should be more readable and beautiful. Compare below code lines.
vs
Which is more readable?

  • Explicit is better than implicit.
    Always use module name with function call so that it is explicitly known which module this function belongs to. So instead of myfunction() , use mymodule.myfunction() .
  • Simple is better than complex.
    Do not write complex code. Your code should be readable. Consider this your code will be used by some psycho killer who knows where you live. Simple code may be lengthier but remember you have to write once but read/maintain the code always.
  • Flat is better than nested.
    Do not use loops inside loops and again inside loops. Or do not use if-else inside if-else inside if-else. Maximum indentation level should not exceed four. Write flat code. Flat code is easy to maintain and read.
    vs
    Try to use second approach.

 

  • Sparse is better than dense.Do not try to fit more code in one line. So instead of
    use

 

  • Readability counts.
    This is simple. Use indented code. Use comments. Read above aphorism.
  • Errors should never pass silently.
    Always log or raise exceptions. Do not do this

 

  • In the face of ambiguity, refuse the temptation to guess.
    Do not write ambiguous code. Do not leave room of guessing. For example before storing data to database, make sure you find out the charset of data  and then decode data into required charset and then store.
  • here should be one, and preferably only one way to do it.
    In python all sequences are iterated in one way.
     

    Rest are easy I think. Let me know what you think of this. Correct me If you think something is not explained correctly.

 

(Visited 269 times, 1 visits today)

You must read this :

Leave a Reply

Your email address will not be published. Required fields are marked *