tips   0   1302
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   1302

Related Articles:
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,...
How to upgrade to paid account on PythonAnyWhere
Which is the best server for hosting Django Apps. Best hosting provider for Django Apps. Cheapest Django Hosting. PythonAnyWhere Reviews. Django Hosting....
Server Access Logging in Django using middleware
Creating access logs in Django application, Logging using middleware in Django app, Creating custom middleware in Django, Server access logging in Django...
How to upload and process the CSV file in Django
How to upload and process the content of csv file in django without storing the file on server. Process CSV content in Django. Uploading and reading csv....

0 thoughts on 'What Is The Meaning Of Different Aphorism In Zen Of Python'
Leave a comment:


*All Fields are mandatory. **Email Id will not be published publicly.


SUBSCRIBE
Please subscribe to get the latest articles in your mailbox.


Recent Posts:






© pythoncircle.com 2018-2019
Contact Us: code108labs [at] gmail.com
Address: 3747 Smithfield Avenue, Houston, Texas