Los 19 Mandamientos

--Originally published at Eduardo's Projectz

Tim Peters, uno de los mas grandes entusiastas de Python, estableció una serie de conceptos que, al día de hoy, son tomados en cuenta como una serie de conceptos que deben ser tomados en cuenta a la hora de programar.

Zen de Python.png

Puedes acceder a estos conceptos simplemente tecleando import this mientras se está corriendo python en la terminal.

Traducción a el Zen de Python:

  1. Hermoso es mejor que feo.
  2. Explícito es mejor que implícito.
  3. Simple es mejor que complejo.
  4. Complejo es mejor que complicado.
  5. Plano es mejor que anidado.
  6. Disperso es mejor que denso.
  7. La legibilidad cuenta.
  8. Los casos especiales no son suficientemente especiales como para romper las reglas.
  9. Aunque lo pragmático gana a la pureza.
  10. Los errores nunca deberían dejarse pasar silenciosamente.
  11. A menos que se silencien explícitamente.
  12. Cuando te enfrentes a la ambigüedad, rechaza la tentación de adivinar.
  13. Debería haber una — y preferiblemente sólo una — manera obvia de hacerlo.
  14. Aunque puede que no sea obvia a primera vista a menos que seas holandés.
  15. Ahora es mejor que nunca.
  16. Aunque muchas veces nunca es mejor que *ahora mismo*.
  17. Si la implementación es difícil de explicar, es una mala idea.
  18. Si la implementación es sencilla de explicar, puede que sea una buena idea.
  19. Los espacios de nombres son una gran idea — ¡tengamos más de esas!

Lo que Peters quiso dar a entender con esto fue, básicamente, que la mejor manera de programar en Python (Y en cualquier idioma) es hacerlo de una forma clara, fácil de entender y comprender el funcionamiento.

Aunque pueda parecer tonto, seguir el Zen de Pyhton en verdad es una manera eficiente de mejorar tu nivel de realización de, no sólo programación, sino de cualquier actividad cotidiana.

Zen de Pyhton: https://github.com/python/peps/blob/master/pep-0020.txt https://www.python.org/dev/peps/pep-0020/

 

images

 

 


#SinComentarios

--Originally published at Eduardo's Projectz

Aunque parezcan irrelevantes a veces, los comentarios son una de las herramientas más importantes que podemos utilizar en el día a día de la programación.

Los comentarios son una excelente forma de explicar al humano como funciona nuestro programa. Esto puede sonar un poco tonto pero en realidad es muy importante el uso de comentarios en muchos aspectos. Desde el trabajo en equipo, donde los comentarios ayudan a que se entiendan los miembros del equipo entre si, hasta un trabajo en solitario que se alarga por mucho tiempo, donde los comentarios pueden ayudar a que no te pierdas y comprendas que estabas haciendo antes más rápido.

Para crear un comentario basta con poner el símbolo gato (“#”) antes de lo que quieras definir como comentario.

captura-de-pantalla-de-2016-09-14-19-32-51

Como he mencionado anteriormente, los comentarios son generalmente utilizados para explicar lineas de código.

captura-de-pantalla-de-2016-09-14-20-19-23

El símbolo gato (“#”) automáticamente marca como comentario todo lo que esté a la derecha de él, no importa si tenias variables declaradas o funciones definidas, si está a la derecha del símbolo gato (“#”) será tomado como comentario y no contará para el desarrollo del código.

captura-de-pantalla-de-2016-09-14-20-29-47

Esta propiedad puede ser aprovechada para probar distintas lineas de código sin eliminarlo.

captura-de-pantalla-de-2016-09-14-20-34-20    captura-de-pantalla-de-2016-09-14-20-38-21

En el caso anterior, el valor de “c” es el que está en la linea 7, ya que las lineas 3 a la 6 están designadas como comentarios y no influyen en el desarrollo del código.

 

Para información más completa, visita: http://www.tutorialpython.com/comentarios-en-python/ http://www.pythonforbeginners.com/comments/comments-in-python http://lineadecodigo.com/python/comentarios-en-python/

Para una explicación más ilustrativa ve el siguiente video-tutorial: https://youtu.be/Uu7C99-hG60

 

 

 

images

 

 


Calling functions

--Originally published at Programming Fundaments

A function, in programming, is used to implement mathematical functions (duh), they are known as subroutines, routines, procedures, methods, etc. A function in Python is defined by a def statement an the normal syntax is wroten as this:

def function-name(Parameter list):
    statements, i.e. the function body

That usually how you write a function in the next blog we are going to go over the function througly

Examples and more information at: http://www.python-course.eu/python3_functions.php


Basic user input

--Originally published at Programming Fundaments

In this post we are going to talk about the function input(). This funtion is basically used to create strings. With this you can create a casting or oval funtion just like this:

name = input("Frank")
print("Nice to meet you " + name + "!")
age = input("42")
print("So, you are are already " + age + " years old, " + name + "!")

And when you run it it should run like this.

$ python input_test.py 
What's your name? "Frank"
Nice to meet you Frank!
Your age? 42
So, you are are already 42 years old, Frank!

For more information check the link down below

Examples from: http://www.python-course.eu/python3_input.php

 

Examples


Basic Output (Print)

--Originally published at Programming Fundaments

One type of basic output for Python 3 y the orint function. This one is simple, just use the print command to print the result create an output for the program. Example:

>>> print(42)
42
>>>

For the command print to work you must have the values inside “(“” )” and with that you can print your values. You can also print severa values at a time by simply separating the with a coma, all inside the parenthesis

Moren information at: http://www.python-course.eu/python3_print.php


Basic data types

--Originally published at Programming Fundaments

Python has 3 standart data types: Numbers, Strings and Lists

Number Data:

Number data types store numeric information (yeah, duh), after you insert a value to them Example:

var1 = 1
var2 = 10

String Data:

Astring, in Python, is defined as a set of character between quotation marks, and the subsets using “[ ] ” and “[ : ]”. Example:

#!/usr/bin/python

str = 'Hello World!'

print str          # Prints complete string
print str[0]       # Prints first character of the string
print str[2:5]     # Prints characters starting from 3rd to 5th
print str[2:]      # Prints string starting from 3rd character
print str * 2      # Prints string two times
print str + "TEST" # Prints concatenated string

Resulting in the next answer:

Hello World!
H
llo
llo World!
Hello World!Hello World!
Hello World!TEST

List data

To write a list you must assign values, using “[]” and “[:]” , and the command “list”. These values order are listed starting at 0, basically making the 0 like a 1 if we refer to the normal way to count numbers (you know, the way they taught you in elementary). Example:

#!/usr/bin/python

list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]
tinylist = [123, 'john']

print list          # Prints complete list
print list[0]       # Prints first element of the list
print list[1:3]     # Prints elements starting from 2nd till 3rd 
print list[2:]      # Prints elements starting from 3rd element
print tinylist * 2  # Prints list two times
print list + tinylist # Prints concatenated lists

Creating the next result:

['abcd', 786, 2.23, 'john', 70.200000000000003]
abcd
[786, 2.23]
[2.23, 'john', 70.200000000000003]
[123, 'john', 123, 'john']
['abcd', 786, 2.23, 'john', 70.200000000000003, 123, 'john']

More examples at:http://www.tutorialspoint.com/python/python_variable_types.htm


Zen of Python

--Originally published at Programming Fundaments

The Zen of python is an entry in the Python Enhancement Proposals (PEP), these are a collection of softeare principals that influences the desings of Python. 19 are written by Tim Peters, an Python pilgrim, these were written among june 1999.

This text is free domain at: https://github.com/python/peps/blob/master/pep-0020.txt

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!



Use of Comments

--Originally published at Programming Fundaments

Comments are, as the name implies, annotacion that you can add up to your work, as such these will not affect your strings in any way , these are just add on that you can use at any given time.

iilusSimply by using “#” python will ignore the text after the sign until the end of the line, python does not take as part of the code.

 


How to install Python (From Cygwin)

--Originally published at Programming Fundaments

This way of instaling Python its more efficient that the normal way, so problably you would want to check out this way before you start programming.

First, install Cygwin with these next packages

python
python-paramiko 
python-crypto  
gcc  
wget 
openssh 

Then, with Cygwin alrady installed, type python in Cygwin

After that install all the toolsetups at: https://pypi.python.org/pypi/setuptools

Inside Cygwin use easy_install to install request and pustil.

And from there on you can use python inside Cywing, and thats one way to start programing

For more information check at: https://github.com/h2oai/h2o-2/wiki/Installing-Python-inside-Cygwin


Necesitas practicar en Python?

--Originally published at Introduction of Programming

El día de hoy fui a la oficina de Ken a preguntar ¿de que forma puedo practicar en Python y saber que estoy haciendo bien? ¿acaso puedo ver algunos resultados de esos problemas? y Ken me guió a su pagina de hace un año en el que dejaba tareas, el link es este, en ese link pueden ver las tareas que dejó, y los resultados pueden verse buscando el código de la tarea (ejemplo: “wsq00 -Sign page one”, el link sería :wsq00) de esa forma podremos ver los resultados de los estudiantes del año pasado

verán algo así…

Screen Shot 2016-08-31 at 10.31.40 PM