====== Guía Python ====== Guía para aprender conceptos básicos de programación junto al lenguaje de programación Python. Ejercicios tomados de [[http://learnpythonthehardway.org/python3/|Learn Python The Hard Way]]. Para conocer algunos conceptos básicos previos, puede visitar: [[https://en.wikiversity.org/wiki/Introduction_to_Programming/About_Programming]] ===== Ejercicios sugeridos: ===== - [[http://learnpythonthehardway.org/python3/ex0.html|Instalación del ambiente]] - [[http://learnpythonthehardway.org/python3/ex1.html|Primer programa]] - [[http://learnpythonthehardway.org/python3/ex2.html|Comentarios]] - [[http://learnpythonthehardway.org/python3/ex3.html|Operaciones matemáticas]] - [[http://learnpythonthehardway.org/python3/ex4.html|Variables]] - [[http://learnpythonthehardway.org/python3/ex5.html|Variables e impresión]] - [[http://learnpythonthehardway.org/python3/ex13.html|Paramétros e imports]] - [[http://learnpythonthehardway.org/python3/ex14.html|Uso de parámetros]] - [[http://learnpythonthehardway.org/python3/ex18.html|Funciones]] - [[http://learnpythonthehardway.org/python3/ex19.html|Funciones y variables]] - [[http://learnpythonthehardway.org/python3/ex25.html|Imports de código creado]] - [[http://learnpythonthehardway.org/python3/ex26.html|Código ajeno]] - [[http://learnpythonthehardway.org/python3/ex27.html|Introducción a la lógica]] - [[http://learnpythonthehardway.org/python3/ex28.html|Práctica de lógica]] - [[http://learnpythonthehardway.org/python3/ex29.html|If]] - [[http://learnpythonthehardway.org/python3/ex30.html|Else]] - [[http://learnpythonthehardway.org/python3/ex31.html|Uso de If y Else]] - [[http://learnpythonthehardway.org/python3/ex32.html|Ciclos]] - [[http://learnpythonthehardway.org/python3/ex33.html|While]] ===== Ejercicios extras: ===== * [[http://learnpythonthehardway.org/python3/ex34.html|Listas]] * [[http://learnpythonthehardway.org/python3/ex38.html|Trabajando con listas]] * [[http://learnpythonthehardway.org/python3/ex39.html|Diccionarios]] ===== Algunos Conceptos ===== =====Temas===== * Hola mundo * Variable e imprimir * Funcion * Clase * Import ====Hola Mundo==== Abra una terminal y ejecute python. Se va a abrir un interpretador de python. print "Hola Mundo" variable_a_imprimir="Hola Mundo 2" print variable_a_imprimir a=2 b=3 c=a+b print c print 2**100 Ahora para salir del interprete de python ejecute el siguiente comando: exit() Vamos a clonar el material con el que se va a estar trabajando. git clone https://github.com/degv364/capacitaciones_python.git ==== Loops, variables, listas==== Vamos a crear el primer programa en python. Vaya al directorio donde quiere tener su programa. emacs fibonacci.py Esto va a abrir emacs para poder editar su programa. #!/usr/bin/env python #imprimir los primeros 100 terminos no triviales de la #serie de Fibonacci def main(): #creamos la variable inicial finonacci_last=1 fibonacci_last_last=1 for i in range(100): #creamos el nuevo termino de laserie fibonacci_current=fibonacci_last+fibonacci_last_last #hacemos update de los 'last' fibonacci_last=fibonacci_current fibonacci_last_last=fibonacci_last #imprimir el resultado print fibonacci_current if __name__=="__main__": main() Ejecute el programa anterior de la siguiente manera: python fibonacci.py Como reto. Escriba el programa de manera que se pueda guardar cada término de la serie en una lista. ====Funciones==== Ahora vamos a trabajar con funciones. Recursividad! emacs factorial.py Ahora vamos a crear nuestra primera clase Vamos a utilizar nuestra clase. Corramos python python number1=complex(1,3) number2=complex(42,45) number1.get_real_part() number2.get_imaginary_part() result=number1+number2 print str(result.get_real_part())+ " + i" + str(result.get_imaginary_part()) ===== Estilos ===== En el Arcos-Lab sugerimos seguir la siguiente [[https://www.python.org/dev/peps/pep-0008/|guía de estilo]] de programación para Python.