Tag Archives: #444444

#mastery08 Python conventions (Zen of Python)

The zen of python is, according to long time Pythoneer Tim Peters, a set of rules you have to follow or at least to take into account while coding in python which are:

Source: https://www.python.org/dev/peps/pep-0020/

08 

1014

Gilberto Rogel García

Mastery22

Repetitions

While: Is used for repeating sections of code until a defined condition is met.

For: Is used when you have a piece of code which you want to repeat n number of times. 

Recursion: Is when a function is called inside de same function.

It depends on what your program is about. While is used for repeting actions. For is used for actions that the function have to do for each element in something. And recursion is when you have some conditions that are going to change the original value and then it have to make the function again.

 

Link: https://github.com/LizethAcosta/Tareas/blob/master/Mastery22

22

 

Basic types and their use in Python

                                                                                                                       @PablO_CVi

Types are a category for things within Python with which Python will work. Types are:

 

integers 
Whole numbers from negative infinity to infinity, such as 1, 0, -5, etc.
float 
Short for “floating point number,” any rational number, usually used with decimals such as 2.8 or 3.14159.
strings 
A set of letters, numbers, or other characters.
tuples 
A list with a fixed number of elements. ie x=(1,2,3) parentheses makes it a tuple.
lists 
A list without a fixed number of elements. ie x=[1,2,3] note the square brackets, a list
dictionaries 
A type with multiple elements i.e. x = {1: ‘a’,’b’: 2,3: 3} where you address the elements with, e.g., a text..

Taken from: http://en.wikiversity.org/wiki/Python/Basic_data_types

Python conventions (Zen of Python)

                                                                                                                       @PablO_CVi

 Many years ago a Pythoneer Tim Peters succinctly channels the BDFL’s guiding principles for Python’s design into 20 aphorisms, only 19 of which have been written down.      

        “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!”(2004, p1).

Recuperado de: https://www.python.org/dev/peps/pep-0020/

 

 

The Zen of Python

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!

—Tim Peters

This series of apparently senseless phrases are what Tim Peters considered the Zen of Python. For me it was quite hard to understand at the beggining, but then I found this page which helped me a lot to understand what this Zen was about. 

They depict in weird poetic way the customs that one should follow when coding, in this case in Python but most of them apply to any programming language, so that your code is not only efficient, but also easy to read and understand by even other people beside you. 

And well the page that I have posted above gives some good examples to the phrases that are stated in the Zen of python. But if you don’t want to look to an example of every line well I will give you a summary. 

When we say that beautifull is better than ugly is a sugestion as to ident the program, no more horrible one long lines that means too much to understand them. Whenever we do, call or whatever something we should show clearly what we have done, so there are the less amount of guesses about our code there can be.

Whenever you have to choose between a bunch of easy code that just screws people’s minds you better choose some complicated but yet fewer functions or chunks of code that can help one follow the thread of your code. And of course avoid those long chains of nested loops or conditionals, they just scream: skip me!!

The other thing that we have to take care of is about making our code too complex just for especial cases, many times we can just point at them by treating errors instead of making our code very difficult to comprehend; trying to not sacrifice too much of its functionality in the process. 

We should always try to solve the things the simpliest way we can, a way to figure out if we are doing it right is trying to explain what we have done, if we can’t; then we have a problem. 

And for last I don’t know if I have got it right, but I guess it’s abaout using variables to store the values of large statements, and use appropiate names for them, not names that don’t have much sense or even you can’t remmember.

This is my of my

Babylonian Method

Long time Pythoneer Tim Peters succinctly channels the BDFL's guiding principles for Python's design into 20 aphorisms, only 19 of which have been written down.