The zen of python is a set of 19 principles that rule the design of the programming language python

1.- Beautiful is better than ugly

This basically means the fact that python is, unlike others, a language restricted by identations and arrangements; in python, identation and order really counts. That’s one of the main reasons of why python is the first programming language that is taught.

Is not the same to write

if (x in y):
s = all

Than to write

if (x in y):
    s = all

The correct way is the second one.

 

2.- Explicit is better than implicit

In a contrast to another programming language that is implicit, JavaScript

in JS, if you type the following line

“55” + 5

JS will IMPLICITLLY take the five as string

On the other hand, in Python that line would result in an error, you have to specify first if both are srtrings or numbers

3.- Simple is better than complex

This can be explained with the cocept of debugging, of fixing your program; If you use a lot of global variables, nesting conditional and other complex methods, you may get to you goal, but if not, seeing and fixing why you didn’t reach that goal is going to be a pain in the feelings.

4.- Complex is better than complicated

To example this concept, we can use the loops for and while, check out this code:

counter = 0
while (counter < 10):
      x = counter/3
      counter = counter + 1

You see, this code is not complex, it is easy to get what it does, but it is too complicated, there are too many steps there; this code can be simplified with a for loop

for e in range(0,11):
     x = e/3

So both codes do the same work, the diference is that one is easier to explain.

5.- Flat is better than nested

We can clear that with the conditionals. Each conditional has two paths, if the condition is met, or not. Those are the two only posibilities; now, i f you start nesting and nesting, the posibilities will grow as the powers of two, and we know it grows fast, in a four-level you will have sixteen posible paths, so things got hard. Imagine you have to debug –

 

6.- Sparse is better than dense

This is just a way of writting, you see, is really easier to read a code when it is well spaced and cute, rather than if it looks like the 380 bus at 7am. personally, I think that this principle has to be in every programming language because it makes it easier to read and manipulate the file itself

 

 

7.- Readibility counts

Just as the last one, it has more benefit to have a well ordene code rather than a 380 bus at 7am; it is easier to detect where have you made a mistake and how to correct it…

 

8.- Special cases are not special enough to break the rules

This means just one thing, everything is an object

 

9.- Altough practicality beats purity

 

10.- Errors should never pass silently

That is why python does not runs when it finds an error

 

11.- Unless explicitly silenced

 

12.- In the face of ambiguity refuse the temptation to guess

Stay stick to the status quo!,  Just dont

1 + ‘1’ dont guess!

 

13.- There should be one obvious way to do it

This gets to an unknown to me part of python, the protocols

 

14.- Altough it may not be that obvious unless you are a dutch

Whuuuut?! 🙁

15.- Now is better tha never

It’s better to fix the rpoblem ASAP because if not, debugging and functionality of further code could be negatibely affected

 

16.–Altough never is often better than now

Sometimes the problems won’t be resolved or would last a lot of time that is better to skipp them

 

17.- If the implementation it’s hard to explain, it’s a bad idea

As it’s says, if it is too complicated to explain, it is too complicated to understand, tus it may be a bad idea.

 

18.- If the implementation it’s easy to explain, it may be a good idea

Well, if it can be read fluently, and explained easylly, it can be a good idea, it MAY be, so don’t assume that if it can be read then it’s ok

 

19.- Namespaces are  one hoonking great idea … let’s do more of those

it all has an order

like local variables, nonlocal variables, the evil global variables, and the built in functions, it has a good hierarchy

 

zen_stones_by_3dbasti

CC BY 4.0 Mastery08: The Zen of Python by charliegdrummer is licensed under a Creative Commons Attribution 4.0 International License.