Blog available for sell
This blog is available for sale. Please 'contact us' if interested.
Advertise with us
tips   0   8123
What is the meaning of different aphorism in zen of python

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

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!


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 .

what is the meaning of different aphorism in zen of python  


Explanation:

Beautiful is better than ugly.

Code should be more readable and beautiful. Compare below code lines.

if (is_valid(a) && b == 0 || s == 'yes')
vs

if is_valid(a) and b == 0 or s == 'yes':
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.

if something:
    if something_again:
        if something_here:
vs

if something:
    do this
if somthing_again:
    do this
Try to use second approach.
 

Sparse is better than dense.

Do not try to fit more code in one line. So instead of

if status: print(status)
use

if status:
    print(status)
 

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

try:
    mylist = get_items()
exception Exception as e:
    pass
return mylist
 

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.

for item in sequence:
 

Rest are easy I think. Let me know what you think of this.

Correct me If you think something is not explained correctly.

tips   0   8123
0 comments on 'What Is The Meaning Of Different Aphorism In Zen Of Python'
Login to comment


Related Articles:
atexit with example
There is an option in python where you can execute a function when the interpreter terminates. Here we will see how to use atexit module....
Improve Your Python Practices: Debugging, Testing, and Maintenance
improving your python skills, debugging, testing and practice, pypi...
How to start with Python Programming - A beginner's guide
starting with python programming, how to start learning python programming, novice to expert in python, beginner to advance level in python programming, where to learn python programming, become expert in python programming...
Adding Robots.txt file to Django Application
Adding robots.txt file in your Django application, Easiest way to add robots.txt file in Django, Django application robots.txt file, Why should you add robots.txt file in your Django Application,...
DigitalOcean Referral Badge

© 2022-2023 Python Circle   Contact   Sponsor   Archive   Sitemap