<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4666877516539627762</id><updated>2011-11-03T00:06:15.500-05:00</updated><title type='text'>Programacion en python</title><subtitle type='html'>Sitio dedicado a la Programacion de python, veremos todo lo que corresponde a este lenguaje y las diferencias en el python 2.x y python 3.x para cuando estemos avanzados abordaremos tal vez el desarroollo de videojuegos con esta belleza de lenguaje.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://pycol.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4666877516539627762/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://pycol.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>creamostuweb</name><uri>http://www.blogger.com/profile/05907170252728070066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>13</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4666877516539627762.post-4980953922967794260</id><published>2011-06-30T23:10:00.002-05:00</published><updated>2011-06-30T23:12:39.472-05:00</updated><title type='text'></title><content type='html'>auque un poco ausente de python ... solo por cuestiones labores y envuelto en el mundo web con java pronto volvere actualizar todos los temas de python!!!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4666877516539627762-4980953922967794260?l=pycol.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pycol.blogspot.com/feeds/4980953922967794260/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://pycol.blogspot.com/2011/06/auque-un-poco-ausente-de-python.html#comment-form' title='3 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4666877516539627762/posts/default/4980953922967794260'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4666877516539627762/posts/default/4980953922967794260'/><link rel='alternate' type='text/html' href='http://pycol.blogspot.com/2011/06/auque-un-poco-ausente-de-python.html' title=''/><author><name>creamostuweb</name><uri>http://www.blogger.com/profile/05907170252728070066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4666877516539627762.post-2408133035263158855</id><published>2009-08-24T15:12:00.003-05:00</published><updated>2009-08-24T15:34:04.574-05:00</updated><title type='text'>INTRODUCCION A MYSQL</title><content type='html'>&lt;div align="justify"&gt;&lt;br /&gt;Este artículo es el primero de toda una serie que ofrecerá MySQL AB con el fin de proporcionar al lectorinformación valiosa sobre el servidor de bases de datos MySQL. Aunque en artículos futuros se tratarán temas más avanzados tales como replicación, ODBC y optimización, se pensó que era prudente si el primer tutorial comenzaba por los conceptos básicos. Por lo tanto, el objetivo de este artículo es informar al lector sobre varios temas relacionados con el funcionamiento básico de MySQL. Una sinopsis de los temas que serán cubiertos se muestra a continuación en la Tabla de contenidos.&lt;/div&gt;&lt;div align="justify"&gt; &lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;Conectándose a MySQL por primera vez&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;El programa cliente de MySQL, también conocido como el monitor de MySQL, es una interfase que le permite a un usuario conectarse a un servidor MySQL, crear y modificar bases de datos, y ejecutar consultas y ver los resultados. Este programa es iniciado ejecutando el comando mysql en el prompt del sistema. En general, la sintaxis de este comando es:&lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;shell&gt; mysql [opciones] [base de datos]&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;En donde [opciones] pueden ser una o más opciones usadas en conjunción con el programa mysql, y [base de datos] es el nombre de la base de datos sobre la que se va a trabajar. Puesto que se asume que es la primera vez que se usa el monitor MySQL, debe tomarse un momento para revisar todas las opciones permitidas al ejecutar el siguiente &lt;/div&gt;&lt;div align="justify"&gt; &lt;/div&gt;&lt;div align="justify"&gt;comando:&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="color:#ff0000;"&gt;shell&gt; mysql --help&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;Éste produce una larga lista de opciones que se pueden usar en conjunción con el programa mysql. Por el momento, sin embargo, la meta principal es simplemente conectarse al servidor de bases de datos. Por lo tanto, hay que ejecutar el siguiente comando:&lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;shell&gt; mysql -u root&lt;/span&gt;&lt;/div&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;div align="justify"&gt;&lt;br /&gt;Deberá de aparecer algo como los siguiente: Welcome to the MySQL monitor. Commands end with ; or \g.&lt;br /&gt;Your MySQL connection id is 8 to server version: 3.23.28-gamma-log Type 'help;' or '\h' for help. Type '\c' to clear the buffer&lt;br /&gt;mysql&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;Felicidades, ahora se encuentra conectado al monitor de MySQL como el usuario root (eltodopoderoso). La primera acción oficial como el líder supremo del servidor de bases de datos MySQL es asegurarse que nadie más pueda declararse en esta posición, haciendo esto posible cuando alguién quiera conectarse como root al servidor deba de proporcionar una contraseña. Hay que cambiar la contraseña de su valor actual (un valor nulo), a algo difícil de adivinar usando el siguiente comando:&lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;mysql&gt;SET PASSWORD FOR 'root'@'localhost' = PASSWORD('la_palabra_secreta');&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;El "root", que es el nombre de usuario, y "localhost", que es el nombre del host, constituyen un usuario único en MySQL. Para aquellos lectores no familiarizado con la terminología de redes, 'localhost' es un nombre usado para referirse al servidor local; en este caso, el servidor sobre el cuál reside MySQL. Por lo tanto, al escribir 'root'@'localhost', este comando le dice al servidor MySQL que ponga la contraseña para un usuario denominado 'root' que se conectará específicamente del servidor local('localhost').&lt;/div&gt;&lt;div align="justify"&gt; &lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;Más específicamente, este comando cambiará la contraseña actualizando lo que se conocecomúnmente como la tabla de privilegios de MySQL. Estas tablas, que se encuentran en la base de datos llamada mysql, contienen información con respecto a las capacidades de conexión y uso de todos los usuarios que intentan usar el servidor de base de datos MySQL. Más específicamente, estecomando actualiza la tabla user, actualizando el campo password de la fila en la cual el valor de campo user es root. El campo password se actualizará con el valor encriptado de la cadena que se pasa como parámetro a la función PASSWORD().&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;Por supuesto, no olvidar esta contraseña. Puesto que ésta es almacena en un texto encriptado dentro de la base de datos, no puede ser recuperada fácilmente en el caso de que sea olvidada.Hay también un método alternativo para actualizar la contraseña:&lt;/div&gt;&lt;div align="justify"&gt; &lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;shell&gt; mysqladmin -u root password 'la_palabra_secreta'&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt; &lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;Este comando tiene el mismo efecto que el comando introducido previamente. Salir y conectarse de nuevo al monitor MySQLPara verificar que la nueva contraseña funciona, salir del monitor MySQL usando el siguiente comando:&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="color:#ff0000;"&gt;mysql&gt; \q&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;Esto nos regresa al shell del sistema. Ahora hay que volver al monitor, pero esta vez usando el siguiente comando:&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="color:#ff0000;"&gt;shell&gt; mysql -u root -p&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;El hacer esto resulta en un prompt para proporcionar la contraseña del usuario root, como se muestra a continuación:&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;Enter password:&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;En este punto, debe de suministrarse la contraseña que se asignó al usuario root previamente. Asumiendo que ésta ha sido proporcionada correctamente, aparecerá el saludo estándar de MySQL, y root será conectado al servidor MySQL una vez más.&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;¡Cuidado con esa contraseña!&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;Muchos lectores pueden estar tentados a incluir la contraseña en la misma línea de comandos, como sigue:&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="color:#ff0000;"&gt;shell&gt; mysql -u root -pla_palabra_secreta&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt; &lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;¡No hacer esto!. ¡No sólo es un método sumamente inseguro para proporcionar la contraseña, sino que no producirá los resultados esperados!. Es inseguro porque permitirá a cualquier persona observar la contraseña en este formato de texto plano, pero también porque cualquier usuario puede usar el comando 'ps' de Unix para ver los comandos que se están ejecutando y ver allí la contraseña en su formato de texto plano. Quizás sea una buena idea almacenar la contraseña en nuestro archivo de configuración my.cnf,localizado en~/.my.cnf . Si usted no sabe lo que es este archivo, lea por favor la sección previa titulada El archivo de configuración de MySQL.&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;Seleccionado una base de datos Por supuesto, simplemente conectarse al servidor MySQL no servirá de mucho. Seguramente se querrá seleccionar una base de datos para trabajar sobre con ella. Esto se puede hacer de dos&lt;br /&gt;maneras:&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;Una de ellas es incluir el nombre de la base de datos al ejecutar el comando mysql. Por ejemplo, para conectarse al servidor MySQL y seleccionar al mismo tiempo la base de datos es:&lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;shell&gt; mysql -u root -p mibasededatos&lt;/span&gt;&lt;/div&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;div align="justify"&gt;&lt;br /&gt;Tal vez cause algo de confusión en algunos lectores, ya que parece que se proporciona la palabra "mibasededatos" como la contraseña del usuario root. Esto no es correcto. Hay que tomarse un momento para revisar la sintaxis que se describe en la salida del comando mysql --help, puesto que debe de ser evidente que "-u root -p" se refiere a la parte de [opciones] y "mibasededatos" a la parte de [base de datos].&lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;La otra manera de seleccionar una base de datos, es cuando uno ya está conectado al servidor MySQL. Para ello se debe usar el siguiente comando:&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="color:#ff0000;"&gt;mysql&gt; use mibasededatos&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;Una vez ejecutado cualquiera de los dos comandos, todas las consultas se dirigirán hacia la base dedatos hipotética mibasededatos.mysqladmin El programa mysqladmin se usa para administrar varios aspectos del servidor de bases de datos MySQL. Al usarlo, el administrador puede realizar las tareas tales como: crear y eliminar bases de datos, dar de baja el servidor MySQL, actualizar las tablas de privilegios, y ver los procesos que se están corriendo (ejecutando) dentro de MySQL. La sintaxis general es:&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="color:#ff0000;"&gt;shell&gt; mysqladmin [opciones] comando(s)&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt; &lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;Dónde [opciones] puede ser toda una serie de opciones usadas en conjunción con el programa mysqladmin. Puesto que se asume que es la primera vez que se usa el programa mysqladmin, se recomienda que se revisen con detalle todas las opciones que se tienen permitidas con este programa.Usar el siguiente comando:&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;shell&gt; mysqladmin --help&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;Esto produce una larga lista de las opciones que se pueden usar en conjunción con el programa de mysqladmin. Para demostrar como son usadas estas opciones, a continuación vamos a decirle a mysqladmin que necesitamos crear una base de datos llamada widgets, la cuál será usada a través del resto de este artículo para ver otras funciones útiles de MySQL.Una base de datos se crea como sigue:&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;shell&gt; mysqladmin -u root -p create widgets&lt;br /&gt;Enter Password:&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;Después de la ejecución, mysqladmin creará la base de datos y regresará el shell del sistema. Típicamente, el siguiente paso consiste en asegurar la nueva base de datos modificando las tablas de privilegios. Los detalles de como se hace esto es el objetivo de la siguiente sección. Lecturas adicionales en la documentación de MySQL (en inglés): 14.5 Administering a MySQL Server Asegurando una base de datos La seguridad debe ser lo primero que debe venir a la mente de un administrador de MySQL después de crear una base de datos. Como se discutió en la sección "Las tablas de privilegios", asegurar una base de datos consiste en hacer modificaciones a las tablas que se encuentran en la base de datos llamada mysql. En esta sección, el lector aprenderá a asegurar la base de datos widgets que se creó anteriormente. Antes de hacer esto, se va a realizar un breve resumen de cómo son modificadas las tablas de privilegios. Hay dos métodos usados para modificar las tablas de privilegios. El primero es a través del uso de las sentencias típicas de SQL tales como INSERT, UPDATE, y DELETE. Sin embargo el uso de este método ha sido depreciado para introducir el segundo método, el cual involucra el uso de los comandos especiales GRANT yREVOKE. Por lo tanto, sólo este método se discutirá a continuación.&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;El comando GRANT&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;La función del comando GRANT es crear nuevos usuarios, y asignarle sus privilegios. Su sintaxis es:&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="color:#ff0000;"&gt;GRANT priv_type [(column_list)] [, priv_type [(column_list)] ...]&lt;br /&gt;ON {tbl_name  *  *.*  db_name.*}&lt;br /&gt;TO user_name [IDENTIFIED BY 'password']&lt;br /&gt;[, user_name [IDENTIFIED BY 'password'] ...]&lt;br /&gt;[WITH GRANT OPTION]&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt; &lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;Una comprensión de cómo trabaja el comando GRANT se obtiene mejor a través de ejemplos. En el ejemplo siguiente, el comando GRANT es usado para agregar un nuevo usuario a la base de datos. Este usuario será usado para accesar a la base de datos widgets:&lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;mysql&gt;GRANT usage ON *.* TO widgetAdmin@localhost&lt;br /&gt;-&gt;IDENTIFIED BY 'ilovewidgets';&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;Esto creará un nuevo usuario denominado widgetAdmin, capaz de conectarse al servidor MySQL vía el localhost usando la contraseña ilovewidgets. Hay que tener presente que sólo se otorgan privilegios de conexión, no se permitirá que el usuario haga nada en el servidor MySQL. Vamos a proseguir cambiándonos a la base de datos mysql y ejecutando la siguiente consulta:&lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;mysql&gt; SELECT * FROM user;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;Nótese que la fila conteniendo el usuario widgetAdmin tiene valores N para todos los demás privilegios.Esto es bueno, puesto que la tabla user contiene privilegios de carácter global. Para clarificar esto, si un valor "Y" se pone para cualquier privilegio en la tabla user, ese usuario puede aplicar ese privilegio a cualquier base de datos de MySQL. Por lo tanto, casi siempre será mejor si todos los privilegios están en "N" dentro de esta tabla. ¿Bien, entonces como se asignan los privilegios a un usuario para una base de datos en particular?. Esto se hace fácilmente modificando ligeramente el comando GRANT del ejemplo previo. Por ejemplo, si asumimos que el administrador quiere otorgar los privilegios SELECT, INSERT, UPDATE y DELETE al usuario widgetAdmin sobre la base de datos widgets, se tendría que usar el comando GRANT de la siguiente manera:&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;mysql&gt;GRANT SELECT, INSERT, UPDATE, DELETE&lt;br /&gt;-&gt;ON widgets.* TO &lt;a href="mailto:widgetAdmin@localhost"&gt;widgetAdmin@localhost&lt;/a&gt;;&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;Después de la ejecución de este comando, el usuario widgetAdmin puede inmediatamente hacer uso de estos privilegios. Los privilegios introducidos aquí no son los únicos disponibles para el administrador. La tabla 1-proporciona un lista de todos los privilegios disponibles. &lt;/div&gt;&lt;div align="justify"&gt; &lt;/div&gt;&lt;div align="justify"&gt;Tabla 1-1: privilegios disponibles para usar con el comando GRANT y REVOKE&lt;/div&gt;&lt;div align="justify"&gt; &lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;ALL PRIVILEGES FILE RELOAD&lt;br /&gt;ALTER INDEX SELECT&lt;br /&gt;CREATE INSERT SHUTDOWN&lt;br /&gt;DELETE PROCESS UPDATE&lt;br /&gt;DROP REFERENCES USAGE&lt;/div&gt;&lt;div align="justify"&gt; &lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;Para ver los nuevos privilegios que han sido asignados, se puede ejecutar la siguiente consulta:&lt;br /&gt;mysql&gt; SELECT * FROM db;&lt;br /&gt;Nótese que una fila ha sido agregada a la tabla "db" para el registro del usuario widgetAdmin, con los&lt;br /&gt;valores "Y" asignados a los campos SELECT, INSERT, UPDATE y DELETE.&lt;br /&gt;Aunque en este ejemplo se mostró como crear un usuario, y posteriormente como asignarle los&lt;br /&gt;privilegios, es posible hacer estos dos pasos en uno solo, al ejecutar el comando GRANT visto&lt;br /&gt;anteriormente, con una ligera variante.&lt;br /&gt;mysql&gt;GRANT SELECT, INSERT, UPDATE, DELETE&lt;br /&gt;-&gt;ON widgets.* TO widgetAdmin@localhost&lt;br /&gt;-&gt;IDENTIFIED BY 'ilovewidgets';&lt;br /&gt;Asumiendo que el usuario widgetAdmin aún no existe cuando se ejecute esta consulta, tanto la tabla&lt;br /&gt;"user", como la tabla "db" serán actualizadas con las registros necesarios.&lt;br /&gt;Por supuesto, el administrador puede revocar los privilegios otorgados en cualquier momento. Éste es el&lt;br /&gt;objetivo que se cubre en la siguiente sección.&lt;br /&gt;La sentencia REVOKE&lt;br /&gt;La sentencia REVOKE es usada para rescindir los privilegios que han sido previamente otorgados a un&lt;br /&gt;usuario. Su sintaxis es la siguiente:&lt;br /&gt;REVOKE priv_type [(column_list)] [, priv_type [(column_list)] ...]&lt;br /&gt;ON {tbl_name  *  *.*  db_name.*}&lt;br /&gt;FROM user_name [, user_name ...]&lt;br /&gt;Como en el caso del comando GRANT, quizás la mejor manera de entender realmente cómo funciona&lt;br /&gt;este comando es experimentado con varios ejemplos. Asumiendo que el administrador tiene la&lt;br /&gt;necesidad de revocar el privilegio DELETE que había sido otorgado al usuario widgetAdmin, se tiene&lt;br /&gt;que ejecutar el comando REVOKE de la siguiente manera:&lt;br /&gt;mysql&gt;REVOKE DELETE ON widgets.*&lt;br /&gt;-&gt;FROM widgetAdmin@localhost;&lt;br /&gt;Un punto que se debe tener presente es que mientras REVOKE puede quitar todos los privilegios&lt;br /&gt;otorgados a un usuario (inclusive los privilegios de conexión), éste no quita al usuario de la tabla de&lt;br /&gt;privilegios. Para ilustrar esto, hay que considerar el siguiente comando:&lt;br /&gt;mysql&gt;REVOKE ALL PRIVILEGES ON widgets.*&lt;br /&gt;-&gt;FROM &lt;a href="mailto:widgetAdmin@localhost"&gt;widgetAdmin@localhost&lt;/a&gt;;&lt;/div&gt;&lt;div align="justify"&gt; &lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;¡Mientras esto tendría como resultado que sean revocados todos los privilegios del usuariowidgetAdmin, éste no borraría registros trascendentes de las tablas de privilegios!. Si lo que se desea es borrar completamente a un usuario de la base de datos se tiene que hacer uso de la sentencia DELETE como sigue:&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="color:#ff0000;"&gt;mysql&gt;DELETE FROM user WHERE user = 'widgetAdmin';&lt;br /&gt;Query OK, 1 row affected (0.00 sec)&lt;br /&gt;mysql&gt;FLUSH PRIVILEGES;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;Cuando ha sido ejecutada esta sentencia, se elimina a un usuario de manera definitiva de la tabla de privilegios. Lecturas adicionales en la documentación de MySQL (en inglés): Grant and Revoke Syntax Respaldos de bases de datos El concepto final discutido en este tutorial es uno verdaderamente importante: respaldos de datos. En esta sección se discuten dos métodos de hacer respaldos de datos y de las estructuras de las bases de datos MySQL, los comandos mysqldump y mysqlhotcopy.mysqldump El comando mysqldump proporciona una manera conveniente para respaldar datos y estructuras de tablas. Hay que notar que mientras el comando mysqldump no es el método más eficiente para crear respaldos (mysqlhotcopy se describe a continuación), éste ofrece un medio conveniente para copiar datos y estructuras de tablas que puede ser usado para "poblar" otro servidor SQL, no importando si se trata, o no de un servidor MySQL. El comando mysqldump puede ser usado para crear respaldos de todas las bases de datos, algunas bases de datos, sólo una de ellas, o incluso ciertas tablas de una base de datos dada. En esta sección se ilustra la sintaxis involucrada con varios posibles escenarios, seguida con unos pocos ejemplos. Usando el comando mysqldump para respaldar sólo una base de datos:&lt;/div&gt;&lt;div align="justify"&gt; &lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="color:#ff0000;"&gt; shell&gt; mysqldump [opciones] nombre_base_datos&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;Usando el comando mysqldump para respaldar varias tablas de una base de datos:&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="color:#ff0000;"&gt;shell&gt; mysqldump [opciones] nombre_base_datos tabla1 tabla2. . . tablaN&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;Usando mysqldump para respaldar varias bases de datos:&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="color:#ff0000;"&gt;shell&gt; mysqldump [opciones] --databases [opciones] nombre_bd1 nombre_bd2...&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt; &lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;Usando mysqldump para respaldar todas las bases de datos:&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="color:#ff0000;"&gt;shell&gt; mysqldump [opciones] --all-databases [opciones]&lt;/span&gt;&lt;/div&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;div align="justify"&gt;&lt;br /&gt;Las opciones pueden ser vistas ejecutando el siguiente comando:&lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;shell&gt; mysqldump --help&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt; &lt;/div&gt;&lt;div align="justify"&gt;- Ejemplos -&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;Respaldar ambos, la estructura y los datos encontrados dentro de la base de datos widgets puede ser&lt;br /&gt;realizado como sigue:&lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;shell&gt; mysqldump -u root -p --opt widgets&lt;/span&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;Alternativamente, quizás se requiera respaldar únicamente los datos, esto es logrado al incluir la opción --no-create-info, lo que significa que no se creen los datos relativos a la creación de las tablas.&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;span style="color:#ff0000;"&gt;shell&gt;mysqldump -u root -p --no-create-info widgets&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;Otra variación es respaldar únicamente la estructura de las tablas, esto es logrado al incluir la opción --nodata, que significa la no creación de los datos de las tablas.&lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;shell&gt;mysqldump -u root -p --no-data widgets&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;Si se está planeando usar mysqldump con el fin de respaldar datos para que puedan ser movidos a otro servidor MySQL, es recomendado que se use la opción "--opt". Esto nos dará un respaldo optimizado de los datos que tendrá como resultado un tiempo más rápido de lectura cuando se quieran cargar los datos en otro servidor MySQL. Mientras mysqldump proporciona un método conveniente para respaldar datos, hay un segundo método, el cuales más rápido, y más eficiente. Esto se describe en la siguiente sección. mysqlhotcopy El comando mysqlhotcopy es un script de Perl que usa varios comandos SQL y del sistema para respaldar una base de datos. Más específicamente éste bloquea las tablas, limpia las tablas, hace una copia, y desbloquea las tablas. Aunque este sea el método disponible más rápido para respaldar una base de datos MySQL, éste se limita a respaldar sólo las bases de datos que residen en la misma&lt;br /&gt;máquina en la cual está siendo ejecutado el comando mysqlhotcopy.&lt;/div&gt;&lt;div align="justify"&gt; &lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;El comando mysqlhotcopy puede ser ejecutado para respaldar una base de datos, varias bases de datos, o sólo las bases de datos cuyo nombre coincida con una expresión regular. En esta sección, se muestra la sintaxis involucrada con cada posible escenario seguida de unos pocos ejemplos. Usando mysqlhotcopy para respaldar sólo una base de datos:&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;shell&gt; mysqlhotcopy [opciones] nombre_bd /ruta/nuevo/directorio Usando mysqlhotcopy para respaldar varias &lt;/div&gt;&lt;div align="justify"&gt; &lt;/div&gt;&lt;div align="justify"&gt;bases de datos:&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;shell&gt; mysqlhotcopy [opciones] nombre_bd1.. nombre_bdN /ruta/nuevo/directorio&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;Usando mysqlhotcopy para respaldar sólo las tablas de una base de datos cuyo nombre coincida con&lt;br /&gt;una expresión regular:&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;shell&gt; mysqlhotcopy [opciones] nombre_bd./expresionregular/&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;Las opciones completas del comando mysqlhotcopy pueden ser vistas ejecutando el siguiente comando:&lt;br /&gt;shell&gt; mysqlhotcopy --help&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;- Ejemplos -&lt;br /&gt;Para usar mysqlhotcopy para respaldar la base de datos widgets al directorio "/usr/mysql/backups/" setiene que ejecutar el siguiente comando:&lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;shell&gt;mysqlhotcopy -u root -p widgets /usr/mysql/backups&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;Un segundo ejemplo asume que la base de datos widgets contiene las tablas "productos2000", "productos2001", "clientes2000", y "clientes2001", con los cuatro digitos representando los datos correspondientes a cada año. Si se desean respaldar las tablas relativas al año "2000", el comando mysqlhotcopy tendría que usarse como sigue:&lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;shell&gt; mysqlhotcopy -u root -p widgets./^.+('2000')$/ /usr/mysql/backups&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;En el ejemplo de arriba, la expresión /^.+('2000')$/ le dice a mysqlhotcopy que respalde sólo las tablas&lt;br /&gt;cuyo nombre finalice con la cadena "2000".&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4666877516539627762-2408133035263158855?l=pycol.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pycol.blogspot.com/feeds/2408133035263158855/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://pycol.blogspot.com/2009/08/introduccion-mysql.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4666877516539627762/posts/default/2408133035263158855'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4666877516539627762/posts/default/2408133035263158855'/><link rel='alternate' type='text/html' href='http://pycol.blogspot.com/2009/08/introduccion-mysql.html' title='INTRODUCCION A MYSQL'/><author><name>creamostuweb</name><uri>http://www.blogger.com/profile/05907170252728070066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4666877516539627762.post-5022733976595347459</id><published>2009-08-24T15:00:00.004-05:00</published><updated>2009-08-24T15:08:45.620-05:00</updated><title type='text'>GUI EN PYTHON</title><content type='html'>&lt;div align="justify"&gt;&lt;span style="color:#ff0000;"&gt;TKINTER:&lt;/span&gt; &lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;TkInter (de TK Interface) es un módulo que nos permite construir interfaces gráficas de usuario multiplataforma en Python utilizando el conocido toolkit Tk. Python incluye este módulo por defecto, lo que hace que sea un tookit muy popular. TkInter, además, es robusto, maduro y muy sencillo de aprender y de utilizar, contando con una amplia documentación. Por otro lado hasta la versión 8.5 Tk era famoso por lo poco atractivo de sus widgets (cosa que se podía solucionar hasta cierto punto gracias a Tile). No es hasta esta versión que contamos con cosas tan básicas como textos con antialiasing en X11 o widgets como Treeview. En esta versión también se incluye Tile por defecto, por lo que contamos con un mejor aspecto general para todas las plataformas. Sin embargo Python no se distribuye con Tk 8.5 hasta la versión 2.6, por lo que, para versiones de Python anteriores, es necesario recompilar TkInter para Tk 8.5 por nuestra cuenta, o bien usar Tile si no necesitamos ninguna de las nuevas características. Es más, para poder usar la mayor parte de las nuevas características de Tk 8.5 es necesario instalar una librería que actúe como wrapper de Ttk (el nombre con el que han dado en llamar al conjunto de los nuevos widgets y temas de Tk), como puede ser pyttk. TkInter se distribuye bajo la PSFL (Python Software Foundation License) una licencia compatible con la GPL creada para la distribución de software relacionado con el proyecto Python. La PSFL carece de la naturaleza viral de la GPL, por lo que permite crear trabajos derivados sin que estos se conviertan necesariamente en software libre. Por último, veamos una pequeña aplicación de ejemplo escrita con TkInter, sin uso de eventos y con solo unos pocos widgets, que nos servirá para comparar el aspecto de los distintos toolkits.&lt;br /&gt;//////////////////////////////////////////////////////////////////&lt;br /&gt;from Tkinter import * root = Tk() frame = Frame(root) frame.pack() label = Label(frame, text="Hola mundo" ) c1 = Checkbutton(frame, text="Uno" ) c2 = Checkbutton(frame, text="Dos" ) entry = Entry(frame) button = Button(frame, text="Aceptar" ) label.pack() c1.pack() c2.pack() entry.pack() button.pack() root.mainloop() ////////////////////////////////////////////////////////////////////// 750) this.width=750" border=0&gt; Pros: Popularidad, sencillez, documentación.&lt;br /&gt;&lt;br /&gt;Contras: Herramientas, integración con el sistema operativo, lentitud. Recomendado para: ¿Prototipos rápidos?&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;WXPYTHON :&lt;/span&gt; &lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;wxPython es un wrapper open source para el toolkit anteriormente conocido como wxWindows: wxWidgets. wxPython es posiblemente el toolkit para desarrollo de interfaces gráficas en Python más popular, superando incluso a TKinter, que, como comentamos, se incluye por defecto con el intérprete de Python. wxPython cuenta con más y mejores widgets que TKinter, y ofrece un muy buen aspecto en todas las plataformas, utilizando MFC en Windows y GTK en Linux. wxPython cuenta además con herramientas muy interesantes como wxGlade, una aplicación RAD para diseñar las interfaces gráficas de forma visual. Sin embargo, la API adolece de una cierta falta de consistencia y un estilo muy alejado de Python y más cercano a C++, ya que, de hecho, uno de sus objetivos es no distanciarse demasiado del estilo de wxWidgets. Esto ha provocado que hayan aparecido distintos proyectos para abstraer al programador de los entresijos del toolkit, como Dabo o Wax, aunque estos han tenido un éxito muy comedido. Tanto wxPython como wxWidgets se distribuyen bajo una licencia "wxWindows Licence", que consiste esencialmente en una LGPL con la excepción de que las obras derivadas en formato binario se pueden distribuir como el usuario crea conveniente. Algunos ejemplos de aplicaciones conocidas creadas con wxPython son DrPython, wxGlade, Boa Constructor, Stani's Python Editor y ABC. Finalmente, a continuación podéis consultar el código de la aplicación de ejemplo:&lt;br /&gt;///////////////////////////////////////////////////////////////////// import wx class Frame(wx.Frame): def __init__(self): wx.Frame.__init__(self, parent=None) panel = wx.Panel(self) text = wx.StaticText(panel, -1, "Hola mundo" ) c1 = wx.CheckBox(panel, -1, label="Uno" ) c2 = wx.CheckBox(panel, -1, label="Dos" ) t = wx.TextCtrl(panel) b1 = wx.Button(panel, -1, label="Aceptar" ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(text, 0, wx.ALL, 0) sizer.Add(c1, 0, wx.ALL, 0) sizer.Add(c2, 0, wx.ALL, 0) sizer.Add(t, 0, wx.ALL, 0) sizer.Add(b1, 0, wx.ALL, 0) panel.SetSizer(sizer) panel.Layout() app = wx.App(redirect=True) Frame().Show() app.MainLoop()&lt;br /&gt;///////////////////////////////////////////////////////////////// 750) this.width=750" border=0&gt; Pros: Popularidad, herramientas, multiplataforma. Contras: API muy poco pythonica. Recomendado para: Desarrollo&lt;br /&gt;multiplataforma.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;PYGTK:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Posiblemente PyGTK sea la segunda opción más utilizada para la creación de interfaces gráficas con Python, solo por detrás de wxPython, con la que compite de tú a tú. PyGTK, como podemos suponer por su nombre, es un binding de GTK, la biblioteca utilizada para desarrollar GNOME. PyGTK cuenta con una API muy clara, limpia y elegante y es, además, muy sencillo de aprender, solo superado en ese aspecto por Tkinter. PyGTK también cuenta con grandes herramientas para construir la interfaz de forma gráfica, como Glade o Gazpacho. Un punto negativo es que, hasta hace poco, era necesario instalar X11 para poder usar PyGTK en Mac OS, dado que GTK no había sido portado. Actualmente se puede utilizar el GTK+ OS X Framework que se encuentra todavía en versión beta. PyGTK se distribuye bajo licencia LGPL. Algunas aplicaciones escritas con PyGTK son Deluge, Exaile, Listen, Envy, WingIDE, DeVeDe o emesene. Veamos el código de la aplicación de ejemplo en &lt;/div&gt;&lt;div align="justify"&gt;PyGTK: ////////////////////////////////////////////////////////////////////// import pygtk import gtk window = gtk.Window(gtk.WINDOW_TOPLEVEL) window.connect("destroy", gtk.main_quit) box = gtk.VBox(False, 0) window.add(box) label = gtk.Label("Hola Mundo" ) c1 = gtk.CheckButton(label="Uno" ) c2 = gtk.CheckButton(label="Dos" ) entry = gtk.Entry() button = gtk.Button("Aceptar" ) box.add(label) box.add(c1) box.add(c2) box.add(entry) box.add(button) window.show_all() gtk.main() /////////////////////////////////////////////////////7 750) this.width=750" border=0&gt;&lt;br /&gt;&lt;br /&gt;Pros: Popularidad, sencillez, herramientas.&lt;br /&gt;Contras: Ligeramente más complicado de instalar y distribuir en Mac OS. Recomendado para: Cualquier tipo de aplicación. Especialmente interesante para Gnome.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;PYQT :&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Es posible que PyQt, el binding de Qt para Python, sea la menos popular de las cuatro opciones, aunque es un toolkit sencillo de utilizar y con muchas posibilidades. Es especialmente interesante para el desarrollo en KDE, dado que Qt es la librería utilizada para crear este entorno. No obstante el interés en Qt no se limita a KDE, sino que es una biblioteca multiplataforma que, además, desde la versión 4, utiliza widgets nativos para las distintas plataformas (anteriormente Qt emulaba el aspecto de la plataforma en la que corría). Como aplicación de RAD se puede utilizar Qt Designer. PyQt utiliza un modelo de licencias similar al de Qt, con una licencia dual GPL/PyQt Commercial. Si nuestro programa es compatible con la licencia GPL, es decir, si vamos a publicar el código fuente y permitir a los usuarios modificar nuestra aplicación, podremos usar PyQt sin más preocupaciones. En caso contrario tendremos que pagar para obtener una licencia comercial. Un par de ejemplos de aplicaciones que usan PyQt son Eric y QTorrent. El código de la aplicación de ejemplo en PyQt tendría el siguiente aspecto:&lt;br /&gt;/////////////////////////////////////////////////////////////////////// import sys from PyQt4.QtCore import * from PyQt4.QtGui import * class Form(QWidget): def __init__(self): QWidget.__init__(self) layout = QVBoxLayout() layout.addWidget(QLabel("Hola mundo" )) layout.addWidget(QCheckBox("Uno" )) layout.addWidget(QCheckBox("Dos" )) layout.addWidget(QLineEdit()) layout.addWidget(QPushButton("Aceptar" )) self.setLayout(layout) app = QApplication(sys.argv) form = Form() form.show() app.exec_&lt;/div&gt;&lt;div align="justify"&gt;() //////////////////////////////////////////////////////////////////7 750) this.width=750" border=0&gt; Pros: Sencillez, herramientas, multiplataforma. Contras: Ligeramente más complicado de instalar y distribuir en Mac OS. Licencia. Recomendado para: Cualquier tipo de aplicación. Especialmente interesante para KDE.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4666877516539627762-5022733976595347459?l=pycol.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pycol.blogspot.com/feeds/5022733976595347459/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://pycol.blogspot.com/2009/08/gui-en-python.html#comment-form' title='2 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4666877516539627762/posts/default/5022733976595347459'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4666877516539627762/posts/default/5022733976595347459'/><link rel='alternate' type='text/html' href='http://pycol.blogspot.com/2009/08/gui-en-python.html' title='GUI EN PYTHON'/><author><name>creamostuweb</name><uri>http://www.blogger.com/profile/05907170252728070066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4666877516539627762.post-757418678589294240</id><published>2009-03-06T17:11:00.008-05:00</published><updated>2009-03-07T20:59:18.947-05:00</updated><title type='text'>EVALUANDO PRIMEROS TEMAS:</title><content type='html'>&lt;span style="color: rgb(204, 204, 204);"&gt;Bueno aqui ire colocando ejercicios de toda indole claro algo muy basico para poner en practica todos los temas basicos vistos hasta ahora:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://pycol.blogspot.com/2009/02/tuplas-en-python.html"&gt;lista&lt;/a&gt;&lt;br /&gt;&lt;a href="http://pycol.blogspot.com/2009/02/tuplas-en-python_27.html"&gt;tuplas&lt;/a&gt;&lt;br /&gt;&lt;a href="http://pycol.blogspot.com/2009/03/diccionarios-en-python.html"&gt;diccionarios&lt;/a&gt;&lt;br /&gt;&lt;a href="http://pycol.blogspot.com/2009/02/expresiones-y-sentencias-en-python.html"&gt;expresiones y sentencias&lt;/a&gt;&lt;br /&gt;&lt;a href="http://pycol.blogspot.com/2009/03/sentencias-condicionales.html"&gt;sentecias condicionales como:&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 102); font-weight: bold;"&gt;if:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;aqui tenemos el if y mostramos como simular el switch el python a traves de un diccionario ya que en python no existe propiamente.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 153, 0);"&gt;while:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;en la parte de los bucles tenemos el while y a traves de un while infinito simulamos un&lt;/span&gt; &lt;span style="color: rgb(255, 153, 0); font-weight: bold;"&gt;do while&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;en&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;Python.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0); font-weight: bold;"&gt;for:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;nuestro famoso for que en python se utliliza para recorrer secuencias ;)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;La entradas de datos con&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(255, 153, 0);"&gt; input()&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;asi que tenemos varios tenemas para poder hacer ejercicios basicos asi que yo ire proponiendo algunos para ver las mejores soluciones posibles y espero que ustedes tambien propongas ejercicios:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204); font-weight: bold;"&gt;EJERCICIO 1:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Traduce las siguientes expresiones matematicas a Python y evalualas. Trata de utilizar el menor numero de parentesis posible.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;a) 2+(3.(6/2))&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;b) 4+6/2+3&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;c) (4/2)^5&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;d)(4/2)^(5+1)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;e)(-3)^2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;f)-(3^2)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204); font-weight: bold;"&gt;EJERCICIO 2:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Son validos los siguientes identificadores:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;1)Identificador&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;2)indice/dos&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;3)dos palabras&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;4)__&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;5)12horas&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;6)hora12&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;7)var!&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;8)from&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;9)uno.dos&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;10)'var'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204); font-weight: bold;"&gt;EJERCICIO 3:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify; color: rgb(204, 204, 204);"&gt;Diseña  un programa que, a partir del valor de la base y de la altura de un triangulo (3 y 5 metros, respectivamente), muestre el valor de su area  (en metros cuadrados).Recuerda que el area A de un triangulo se puede calcular a partir de la base b y la altura h como A = bh/2.&lt;br /&gt;&lt;/div&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;                     &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204); font-weight: bold;"&gt;EJERCICIO 4:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Escribe un programa en Python para pasar un número de binario a decimal y de decimal a binario.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204); font-weight: bold;"&gt;EJERCICIO 5:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Escribe un programa en Python que reciba dos listas y devuelva los elementos comunes a ambas, sin repetir ninguno (intersección de conjuntos).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204); font-weight: bold;"&gt;EJERCICIO 6:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Escribe un programa en Python que reciba dos listas y devuelva los elementos que pertenecen a una o a otra, pero sin repetir ninguno (unión de conjuntos).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204); font-weight: bold;"&gt;EJERCICIO 7:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;/span&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; Escribe un programa en Python que reciba dos listas y devuelva los elementos que pertenecen a la primera pero no a la segunda, sin repetir ninguno (diferencia de conjuntos).&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204); font-weight: bold;"&gt;EJERCICIO 8:&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Escribe un programa en Python que, dada una lista de números,devuelva otra lista que sólo incluya los números impares.&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 204, 204); font-weight: bold;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 204, 204); font-weight: bold;"&gt;EJERCICIO 9:&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 204, 204); font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Escribe un programa en Python que, dada una lista de nombres y unaletra, devuelva una lista con todos los nombres que empiezan por dicha letra.&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 204, 204); font-weight: bold;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 204, 204); font-weight: bold;"&gt;EJERCICIO 10:&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 204, 204); font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Escribe un programa en Python que, dada una lista de números,devuelva otra lista con sólo aquellos números que son primos.&lt;/span&gt;&lt;span style="color: rgb(0, 204, 204); font-weight: bold;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 204, 204); font-weight: bold;"&gt;EJERCICIO 11:&lt;/span&gt;&lt;span style="color: rgb(0, 204, 204); font-weight: bold;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Escribe un programa en Python que, dadas dos listas de números,devuelva una lista con todos los pares de números que podemos formar con uno de la primera lista y otro de la segunda.&lt;/span&gt;&lt;span style="color: rgb(0, 204, 204); font-weight: bold;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 204, 204); font-weight: bold;"&gt;EJERCICIO 12:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Escribe un programa en Python que, dada una lista de cadenas, devuelva la cadena más larga. Si dos o más cadenas miden lo mismo y son las más largas, la función devolverá una cualquiera de ellas.&lt;/span&gt;&lt;span style="color: rgb(0, 204, 204); font-weight: bold;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 204, 204); font-weight: bold;"&gt;EJERCICIO 13:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 204, 204); font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Escribe un programa en Python que, dada una lista de cadenas, devuelva una lista con todas las cadenas más largas, es decir, si dos o más cadenas miden lo mismo y son las más largas, la lista las contendrá a todas.&lt;/span&gt;&lt;span style="color: rgb(0, 204, 204); font-weight: bold;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 204, 204); font-weight: bold;"&gt;EJERCICIO 14:&lt;/span&gt;&lt;span style="color: rgb(0, 204, 204); font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;br /&gt;Escribe un programa en Python que reciba una lista de cadenas y devuelva el prefijo común más largo. Define una función que, dado un número de DNI, devuelva la letra&lt;/span&gt;&lt;span style="color: rgb(0, 204, 204); font-weight: bold;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 204, 204); font-weight: bold;"&gt;EJERCICIO 15:&lt;/span&gt;&lt;span style="color: rgb(0, 204, 204); font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;br /&gt;que le corresponde: dividir el número por 23 y utilizar el resto como índice de la cadena "TRWAGMYFPDXBNJZSQVHLCKE".&lt;/span&gt;&lt;span style="color: rgb(0, 204, 204); font-weight: bold;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 204, 204); font-weight: bold;"&gt;EJERCICIO 16:&lt;/span&gt;&lt;span style="color: rgb(0, 204, 204); font-weight: bold;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Diseña un programa que lea una cadena y un entero k y muestre todas las subcadenas de longitud k.&lt;/span&gt;&lt;span style="color: rgb(0, 204, 204); font-weight: bold;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(0, 204, 204);"&gt;EJERCICIO 17:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 204, 204);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;reescriba el codigo para que sea funcional en Python 3.x&lt;/span&gt;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(0, 204, 204);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;div style="color: rgb(51, 255, 51);" class="codigo"&gt; &lt;p&gt;&lt;span class="idle-rese"&gt;print&lt;/span&gt; Dime tu nombre, nombre&lt;/p&gt;  &lt;p&gt;nombre = int(raw_imput())&lt;/p&gt;  &lt;p&gt;&lt;span class="idle-rese"&gt;print&lt;/span&gt; Hola nombre&lt;/p&gt; &lt;/div&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 204, 204);"&gt;EJERCICIO 18:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;La idea es hacer un algoritmo que el ordenador elije un numero y nosotros tenemos que adivinarlo en menos de los intentos que le digamos.&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;El ordenador nos dará pistas de si nuestro numero es mayor o menor que el secreto.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Ayuda:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;import&lt;/span&gt; &lt;span style="color: rgb(204, 255, 255);"&gt;random&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 204, 204);"&gt;EJERCICIO 19:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Realiza el juego del ahorcado:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;a)con listas&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;b)sin listas&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;por ahora la palabra adivinar sera una variable ejem: palabra="adiviname", el maximo de oportunidades el que mejor les parezca.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;se gana:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;cuando se obtenga la palabra oculta por completo antes de agotar nuestro numero de oportunidades.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;se pierde:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;finaliza nuestro maximo de oprtunidades sin descubrir  la palabra oculta&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;A Programar!!!!&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4666877516539627762-757418678589294240?l=pycol.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pycol.blogspot.com/feeds/757418678589294240/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://pycol.blogspot.com/2009/03/evaluando-primeros-temas.html#comment-form' title='8 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4666877516539627762/posts/default/757418678589294240'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4666877516539627762/posts/default/757418678589294240'/><link rel='alternate' type='text/html' href='http://pycol.blogspot.com/2009/03/evaluando-primeros-temas.html' title='EVALUANDO PRIMEROS TEMAS:'/><author><name>creamostuweb</name><uri>http://www.blogger.com/profile/05907170252728070066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4666877516539627762.post-3279214609916795931</id><published>2009-03-06T12:34:00.006-05:00</published><updated>2009-03-06T17:09:51.255-05:00</updated><title type='text'>ENTRADA DE DATOS EN PYTHON</title><content type='html'>&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Que seria de un progama sin la interaccion con los  usuarios :) pues no servirian de a mucho, bueno sin tanto rodeos veamos:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;br /&gt;def main():&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;n = int(input("Digite:"))&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;print (n*2)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;if __name__=="__main__":main()&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;En&lt;span style="color: rgb(255, 102, 102);"&gt; Python 2.x&lt;/span&gt; tenemos &lt;span style="color: rgb(51, 204, 255);"&gt;input() &lt;/span&gt; para capturar &lt;span style="font-style: italic;"&gt;enteros y float&lt;/span&gt; y &lt;span style="color: rgb(51, 204, 255);"&gt;raw_input() &lt;/span&gt;&lt;span style="color: rgb(51, 204, 255);"&gt; &lt;/span&gt;para cadenas pero desde &lt;span style="color: rgb(255, 102, 102);"&gt;python3.x&lt;/span&gt; solo existe &lt;span style="color: rgb(51, 204, 255);"&gt;input() &lt;/span&gt;y el valor que capture es siempre una cadena asi que si queremos que sea entero lo covertimos con la funcion &lt;span style="color: rgb(0, 153, 0);"&gt;int() &lt;/span&gt;y si queremos un float con la funcion &lt;span style="color: rgb(0, 102, 0);"&gt;float()&lt;/span&gt; convertimos el dato capturado a float asi:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;def main():&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;n = float(input("Digite:"))&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;print (n*2)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;if __name__=="__main__":main()&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;para capturar una simple cadena de texto seria:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;def main():&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;n = input("Digite:")&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;print (n*2)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;if __name__=="__main__":main()&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Bueno si queremos validar datos para eso tenemos las excepciones en python pero ese tema lo veremos mas adelante por ahora miren un ejemplo que hize para capturar solo un entero:&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;br /&gt;def main():&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;while True:&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;______&lt;/span&gt;try:&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;______&lt;/span&gt;n = int(input("Digite:"))&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;______&lt;/span&gt;break&lt;br /&gt;           &lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;except:&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;______&lt;/span&gt;print ("Solo digite enteros")&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;if __name__=="__main__":main()&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Bueno lo que hize es hacer un ciclo infinito de esta forma simulamos una do-while de otros lenguaje con python capturo un valor por teclado y si es entero break rompe el ciclo y termina, pero sino se produce una excepcion en python pero como definimos nuestro propio except nos muestra el mensaje de &lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Solo digite enteros y vuelve a pedir que digite  hasta que sea un entero :)&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4666877516539627762-3279214609916795931?l=pycol.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pycol.blogspot.com/feeds/3279214609916795931/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://pycol.blogspot.com/2009/03/entrada-de-datos-en-python.html#comment-form' title='5 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4666877516539627762/posts/default/3279214609916795931'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4666877516539627762/posts/default/3279214609916795931'/><link rel='alternate' type='text/html' href='http://pycol.blogspot.com/2009/03/entrada-de-datos-en-python.html' title='ENTRADA DE DATOS EN PYTHON'/><author><name>creamostuweb</name><uri>http://www.blogger.com/profile/05907170252728070066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4666877516539627762.post-2795179593727202224</id><published>2009-03-05T22:02:00.016-05:00</published><updated>2009-03-06T12:16:49.780-05:00</updated><title type='text'>SENTENCIAS CONDICIONALES</title><content type='html'>&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Para escribir programas utiles, casi siempre necesitamos la capacidad de comprobar ciertas condiciones y cambiar el comportamiento del programa segun la condicion presente. Las sentencias condicionales nos dan esta capacidad. La forma mas  asencilla es la sentencia if:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0); font-weight: bold;"&gt;SENTENCIA IF:&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;def main():&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;    numero=-8&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;    if numero &gt; 0:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;        &lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;print"positivo"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;    else:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;        &lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;print"negativo"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;    &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;    &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;if __name__ == "__main__":main() &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;como vemos manejo un if con un else si numero es mayor que cero imprima positivo else (sino)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;pues imprima negativo asi de sencillo :)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;ok aqui tenemos otra:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;if numero &lt; style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;print “Negativo”&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;elif numero &gt; 0:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;print “Positivo”&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;else:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;print “Cero”&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;   &lt;/span&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;el primer lugar verifica que numero sea menor que cero si se evalua con verdadera imprime negativo y elif y else se ignoran, pero si numero no es negativo pregunto si es mayor que 0, si se evalua como verdadera imprimo positivo y else se ignora, si el numero no es negativo ni mayor a cero pues blanco es y gallina lo pone :) pues el ultimo else imprime cero ya que evaluaron como false el if y el elif.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Bueno ahora biene el switch pero momento en  python no existe :(  pero se podria emular con un simpl&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;e&lt;/span&gt; &lt;a href="http://pycol.blogspot.com/2009/03/diccionarios-en-python.html"&gt;diccionario&lt;/a&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;:) veamos como:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre  style="color: rgb(51, 255, 51);font-family:arial;" class="source-python"&gt;&lt;span style="color: rgb(255, 204, 255);"&gt;def hola():&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;&lt;span style="color: rgb(255, 204, 255);"&gt;print "hola"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 255);"&gt;def adios():&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;&lt;span style="color: rgb(255, 153, 255);"&gt;print "Bye"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;def defecto():&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;_____&lt;/span&gt;&lt;span style="color: rgb(51, 204, 255);"&gt;print "soy el default"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 255, 255);"&gt;def main():&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;switch = {&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;0:hola,&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;1:adios&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;    &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;}&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;switch.get(5,defecto)()&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;if __name__ == "__main__":main() &lt;/pre&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Bueno defini tres funciones hola() que solo imprime hola, adios() que solo se despide y la funcion default o por defecto si se acuerda para lo que han trabajado en otros lenguajes esta se ejecuta cuando si dentro de las opciones switch no coinciden con ninguna pues pasa a ejecutar dicha funcion, lo que llame switch ={0:hola,1:adios} este es nuestro &lt;/span&gt;&lt;a style="color: rgb(102, 51, 102);" href="http://pycol.blogspot.com/2009/03/diccionarios-en-python.html"&gt;diccionario&lt;/a&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; y con la funcion get que esta explicada en el post de&lt;/span&gt; &lt;a style="color: rgb(102, 51, 102);" href="http://pycol.blogspot.com/2009/03/diccionarios-en-python.html"&gt;diccionario&lt;/a&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;la funcion busca  la key que le paso como argumento si la encuentra en el diccionario me ejecuta la funcion segun la key si no pues me ejecuta la funcion que le paso como parametro opcional en ese caso de no encontrar una key en especifico en el diccionario, como ven yo le paso 5 al buscar el el diccionario solo existe el 0 y el 1 asi que no existe dicho key y al pasar eso pues me imprime mi funcion por defecto () :) si le pasan el 1 pues va imprimir adios, bueno solo practiquen y si les da algun error me lo hacen saber ;)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 153, 0);"&gt;BUCLES:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Mientras que los condicionales nos permiten ejecutar distintos fragmentos de código dependiendo de ciertas condiciones, los bucles nos permiten ejecutar un mismo fragmento de código un cierto número de veces, mientras se cumpla una determinada condición.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 153, 0);"&gt;WHILE():&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Veamos un ejemplo pra ver como funciona el while  imprimiendo los numeros del 1 al 10:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;def main():&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;i=1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;while i &lt;= 10:  &lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;print i&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; ____&lt;/span&gt;i+=1 &lt;/span&gt;&lt;/div&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;if __name__ == "__main__":main()&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Bueno esto es muy facil tambien aqui i inicia valiendo 1 el cual while lo evalua preguntando  si i en menor o igual a 10 en caso de ser verdadero ejecuta el print y aumenta en uno el i la expresion &lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;i+=1 es igual que decir i=i+1 o i++ ahora i vale 2 y pregunta de nuevo 2 es menor o igual a 10 verda!!! pues imprime i y aumenta  la i y ahora vale 3 bueno en ese ciclo va dura hasta que llegue a 10 y pregunta 10 es menor o igual a 10 verda!! son igual imprime 10 y aumenta i y ahora vale 11 vuelve y pregunta 11 es menor o igual 10 ni menor ni gual asi que falso!!!! y termina el ciclo :)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;una explicacion muy prekinder pero vale si sos totalmende principiante :)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;tambien lo podemos hacer en un ciclo infinito y preguntar que si llego a 10 para romper nosotros mismos el ciclo:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;def main():&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;___&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;i=1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;___&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;while True:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;_____&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;print i&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;_____&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;if i==10:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;________&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;break&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;      i+=1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;if __name__ == "__main__":main()&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Aqui lo que hago es un ciclo infinito no saben que es infinito ?? pues eliminen del algoritmo el break y lo corren asi y me dicen si algun dia termina de ejecutarse :) aqui el simpre va imprimir  i&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;que incia en 1 bueno la imprime y de inmediato preguntamos que si la i vale 10 sino aumenta en 1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;asi sigue imprimiendo 1 2 3 4 5 6 7 8 9 10 cuando llega a 10 se jecuta el break que rompe el ciclo infinito en caso de eliminar el break siguira imprimiendo sin terminar nunca 11 12 13 14 15 ...........................................................................................................................................................................&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;ahora miren este:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;def main():&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;__&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;i=1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;__&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;print i&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;__&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;while True:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;if i==10:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;______&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;break&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;i+=1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;if i % 2 == 0:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;______&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;continue&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;      print i&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;if __name__ == "__main__":main()&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;cual sera el resultado de este codigo ?????? bueno  se los dejo de tarea :) pero les voy a explicar que hace continue pues simplemente salta a la proxima iteracion &lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;:D bueno por esta vez lo voy a explicar el print que esta fuera del while me imprime 1 ya que i la inicie en 1 :) bueno entramos al ciclo infinito  i==10 falso ya que 1 no es igual a 10 pues no ejecuta el break asi que seguimos i+=1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;ahora desde aqui i vale 2 ;) ahora pregunta if % 2 == 0 pues aqui solo digo si el modulo de la division es igual a 0  si es verdadero pues nuestro numero es par ahora como nuestra i vale 2 es par asi que ejecuta continue y esto hace que salte a la siguiente iteracion asi que ignora el print y pasa a la siguiente iteracion, asi que esto al final me va imprimir solo numeros impares :)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0); font-weight: bold;"&gt;FOR ...IN&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;secuencia = [“uno”, “dos”, “tres”]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;for elemento in secuencia:&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;print elemento&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Los for en python se utilizan para recorrer secuencias en el caso anterior utlize una&lt;/span&gt;&lt;a style="color: rgb(204, 204, 204);" href="http://pycol.blogspot.com/2009/02/tuplas-en-python.html"&gt; lista&lt;/a&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;, el algoritmo es sencillo para cada elemento en la secuencia imprima elemento asi se lee de una forma natural bueno la primera vez  elemento contiene uno imprime uno, la segunda contiene dos e imprime dos, la tercera elemento contiene tres e imprime tres asi va elemento por elemento hasta el final de la secuencia, los que han programado en C/C++ saben que el for lo han utilizado para iterar sobre las posiciones y no sobre los elementos&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 102);"&gt;int mi_array[] = {1, 2, 3, 4, 5};&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 102);"&gt;int i;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 102);"&gt;for(i = 0; i &lt;&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 102);"&gt;    printf(“%d\n”, mi_array[i]);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;El enfoque e Python es mucho mas natural :)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Bueno si muy bonito pero en C/C++ para imprimir numero del 50 al 100 con for es muy facil pero como le hago con python ??? no me digas que tengo que contruir una lista del 50 al 100 para&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;luego recorrerla con for :( pues si pero para eso existe range() una funcion para generar secuencias de numeros veamos:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;def main():&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;___&lt;/span&gt;i=range(50,101)&lt;/span&gt;   &lt;span style="color: rgb(204, 51, 204);"&gt;#si estan con Python3 hacen&lt;/span&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;i=list(range(50,101))&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;___&lt;/span&gt;for numero in i:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;_____&lt;/span&gt;print numero&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;if __name__ == "__main__":main() &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4666877516539627762-2795179593727202224?l=pycol.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pycol.blogspot.com/feeds/2795179593727202224/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://pycol.blogspot.com/2009/03/sentencias-condicionales.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4666877516539627762/posts/default/2795179593727202224'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4666877516539627762/posts/default/2795179593727202224'/><link rel='alternate' type='text/html' href='http://pycol.blogspot.com/2009/03/sentencias-condicionales.html' title='SENTENCIAS CONDICIONALES'/><author><name>creamostuweb</name><uri>http://www.blogger.com/profile/05907170252728070066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4666877516539627762.post-1558392413915837684</id><published>2009-03-03T23:41:00.031-05:00</published><updated>2009-03-04T17:49:38.063-05:00</updated><title type='text'>FUNCIONES EN PYTHON</title><content type='html'>&lt;span style="color: rgb(204, 204, 204);"&gt;Bueno un funcion es una sencuencia de codigo definido por nosotros y  que se ejecuta al hacer referencia a ella por un nombre que definimos&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;,  la sintaxis es la siguiente:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;def&lt;/span&gt;  &lt;span style="color: rgb(255, 204, 204);"&gt;nombre&lt;/span&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;(lista de parametros)&lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);"&gt;:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 255);"&gt; sentencias&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;bueno aqui no es como en C o java que el contenido de una funcion lo determina { }  aqui en python su creador &lt;a href="http://es.wikipedia.org/wiki/Guido_van_Rossum"&gt;Guido Van Rossum&lt;/a&gt; quiso que fuera determinado a traves de la &lt;a href="http://es.wikipedia.org/wiki/Sangr%C3%ADa_%28tipograf%C3%ADa%29"&gt;sangria&lt;/a&gt; con un estandar de 4 espacios veamos para que me entiendan:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;def&lt;span style="color: rgb(255, 102, 102);"&gt; numeros&lt;/span&gt;():&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;print ("hola")&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;          ____&lt;/span&gt;print ("mundo")&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 102);"&gt;def&lt;/span&gt; &lt;span style="color: rgb(255, 102, 102);"&gt;numeros&lt;/span&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;():&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; ____&lt;/span&gt;print ("hola")&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;print ("mundo")&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;como ven aparentemente este par de funciones hacen lo mismo pero hay una diferencia y es que en la primera al llamar la funcion numeros() imprimira hola y acontinuacion mundo ya que como se dan cuenta las dos estan perfectamente aliniadas con una sangria de 4 espacios apartir del nombre de la funcion, cuando rompoes esta sangria como es en el caso de la segunda funcion al llamar numeros() solo imprime hola, y el fin de esto es que Python quiere que escrbas codigo elegante, entendible que llegue otro programador y al ver el fuente de un compañero sea totalmente claro y no un nido de pajaros como muchos estan acostumbrados a programar.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;En Python usted puede llamar las funciones como quiere excepto que utlize alguna palabra reservada algunas mencionadas en&lt;/span&gt; &lt;a href="http://pycol.blogspot.com/2009/02/variables-en-python.html"&gt;VARIABLES DE PYTHON&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Nuestras funciones en python aceptan un sin nuemeros de argumentos , tambien podemos asignar valores por defecto a nuestros parametros, y a todas esta que diferencia hay entre argumentos y parametros??? bueno cuando hago llamado a una funcion:&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;numeros(2,7)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;esos valores son los argumentos de la funcion y cuando hablo de parametros se refiere ya al valor recibido, osea es la variable que defini cuando cree la funcion para que reciba los argumentos:&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;def&lt;/span&gt; numeros&lt;span style="color: rgb(255, 153, 102);"&gt;(x,y):&lt;/span&gt; #las variable X y Y son los parametros de la funcion&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;       &lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;return x+y&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;otra cosa a tener en cuenta es saber que diferencia hay entre procedimiento y funcion ????&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;bueno un procedimiento es una funcion que no retorna ningun valor, y una funcion si retorna un valor, mencino esto porque en python no existen los procedimientos ya que si usted en una funcion no definen un valor a retonar Python por defecto retorna None asi que esto es de tener siempre en cuenta.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;hasta ahora todo lo que hemos visto lo hemos practicado directamente desde consola. ahora en adelante ire colocando el fuente completo para que usted ejecuten su codigo y vayan acostumbrarse a realizar su codigo y sepa reutilizar las funciones de codigos hechos por usted.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;este codigo lo guardan en un archivo que lo pueden llamar como quiera en este caso lo llamare suma.py&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 102);"&gt;def&lt;/span&gt; &lt;span style="color: rgb(102, 255, 153);"&gt;suma&lt;/span&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;(x,y):&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;______&lt;/span&gt;&lt;span style="color: rgb(255, 102, 102);"&gt;"""Esta funcion devuelve la suma de dos enteros"""&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;______&lt;/span&gt;&lt;span style="color: rgb(255, 153, 102);"&gt;return x+y&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 102);"&gt;def&lt;/span&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;main&lt;/span&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;():&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;print suma&lt;span style="color: rgb(255, 153, 0);"&gt;(5,6)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;if &lt;span style="color: rgb(255, 255, 153);"&gt;__name__&lt;/span&gt; ==&lt;span style="color: rgb(255, 255, 102);"&gt; "__main__"&lt;/span&gt;:main&lt;span style="color: rgb(255, 153, 0);"&gt;()&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;y ahora para ejecutarlo solo hacemos:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-weight: bold; color: rgb(204, 204, 204);"&gt;python suma.py   &lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;en nuestra consola Linux o windows&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;, tambien podemos bajar el IDE&lt;/span&gt; &lt;a href="http://download.netbeans.org/netbeans/6.5/python/ea/"&gt;NetBeans&lt;/a&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;solo dedicado a python vamos a utilizar este ya que desde la misma pagina lo puedes bajar tanto para windows como para &lt;span style="color: rgb(255, 102, 102);"&gt;GNU-Linux&lt;/span&gt;.&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 102);"&gt;Para los windowseros:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;Bueno para los usuarios de windows solo lo descargan y doble-click y dan siguiente a todo :)&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 102);"&gt;para los linuxeros:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;p style="color: rgb(204, 204, 204);"&gt;Para poder ejecutar el archivo, abre una linea de comandos y en la carpeta donde está el archivo ingresa comando:&lt;/p&gt; &lt;pre style="color: rgb(153, 153, 255);"&gt;chmod +x netbeans-6.5-python-linux.sh&lt;/pre&gt; &lt;p style="color: rgb(204, 204, 204);"&gt;y despues podemos ejecutarlo:&lt;/p&gt; &lt;pre&gt;&lt;span style="color: rgb(153, 153, 255);"&gt;./netbeans-6.5-python-linux.sh&lt;/span&gt;&lt;br /&gt;&lt;span id="more-118"&gt;&lt;/span&gt;&lt;/pre&gt; &lt;p style="color: rgb(204, 204, 204);"&gt;Eso va a lanzar el instalador y desde ahi recordamos viejos tiempos con windows :)&lt;/p&gt;&lt;p style="color: rgb(204, 204, 204);"&gt;bueno una vez instalado lo abrimos y esta es su ventana principal:&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_BXBLWp3PDyI/Sa7hI2snv9I/AAAAAAAAABo/t7ztseXzVjg/s1600-h/principal"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px; height: 300px;" src="http://3.bp.blogspot.com/_BXBLWp3PDyI/Sa7hI2snv9I/AAAAAAAAABo/t7ztseXzVjg/s400/principal" alt="" id="BLOGGER_PHOTO_ID_5309428552954265554" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Damos File (archivo) y luego en New project (nuevo projecto) y se nos abra la siguiente ventana:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_BXBLWp3PDyI/Sa7jGKY_obI/AAAAAAAAABw/PtEghqhqoxU/s1600-h/Pantallazo2.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px; height: 300px;" src="http://4.bp.blogspot.com/_BXBLWp3PDyI/Sa7jGKY_obI/AAAAAAAAABw/PtEghqhqoxU/s400/Pantallazo2.png" alt="" id="BLOGGER_PHOTO_ID_5309430705724301746" border="0" /&gt;&lt;span style="display: block;" id="formatbar_Buttons"&gt;&lt;span class="on down" style="display: block;" id="formatbar_Bold" title="Negrita" onmouseover="ButtonHoverOn(this);" onmouseout="ButtonHoverOff(this);" onmouseup="" onmousedown="CheckFormatting(event);FormatbarButton('richeditorframe', this, 3);ButtonMouseDown(this);"&gt;&lt;img src="http://www.blogger.com/img/blank.gif" alt="Negrita" class="gl_bold" border="0" /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;dejamos la opcion por defecto Python project y damos next (siguiente) y definimos en nombre de projecto y en donde dice Create main file le cambiamos el nombre por el de nuestro programita&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;suma.py&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;damos finish para volver a nuestra ventana principal&lt;/span&gt;:&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_BXBLWp3PDyI/Sa7mySOSJtI/AAAAAAAAAB4/KjnUsf5UC_8/s1600-h/Pantallazo3.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px; height: 300px;" src="http://4.bp.blogspot.com/_BXBLWp3PDyI/Sa7mySOSJtI/AAAAAAAAAB4/KjnUsf5UC_8/s400/Pantallazo3.png" alt="" id="BLOGGER_PHOTO_ID_5309434762275989202" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Aqui damos doble click al nombre del proyecto que este caso lo llame  estudio y luego en sources donde va estar nuestro primer programa:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;img src="file:///tmp/moz-screenshot.jpg" alt="" /&gt;&lt;br /&gt;&lt;span style="display: block;" id="formatbar_Buttons"&gt;&lt;span class="on" style="display: block;" id="formatbar_Add_Image" title="Añadir imagen" onmouseover="ButtonHoverOn(this);" onmouseout="ButtonHoverOff(this);" onmouseup="addImage();" onmousedown="CheckFormatting(event);;ButtonMouseDown(this);"&gt;&lt;img src="http://www.blogger.com/img/blank.gif" alt="Añadir imagen" class="gl_photo" border="0" /&gt;&lt;/span&gt;&lt;/span&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_BXBLWp3PDyI/Sa7nFXjQ9mI/AAAAAAAAACA/GFqQd8wYbPg/s1600-h/Pantallazo4.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px; height: 300px;" src="http://2.bp.blogspot.com/_BXBLWp3PDyI/Sa7nFXjQ9mI/AAAAAAAAACA/GFqQd8wYbPg/s400/Pantallazo4.png" alt="" id="BLOGGER_PHOTO_ID_5309435090123683426" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Bueno esto no es un tutorial de Netbeans asi que busquen en google un buen tutorial para el manejo completo de esta Herramienta aqui esta el codigo fuente de suma.py en mi compu yo lo llame estudio.py veamos:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;suma.py&lt;br /&gt;---------&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;def suma(x,y):&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;        """Esta funcion devuelve la suma de dos enteros"""&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 204);"&gt;        return x+y&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 255, 153);"&gt;def main():&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 255, 153);"&gt;    print suma(5,5)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 255, 255);"&gt;if __name__ == "__main__":main()&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 102);"&gt;Bueno continuamos viendo las funciones en python:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 204, 153);"&gt;def hola(veces=1):&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;&lt;span style="color: rgb(255, 204, 153);"&gt;print("hola" * veces)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;esta funcion llamada hola contiene un parametro opcional ya que dicho parametro tiene un valor por defecto que es 1, al llamar la funcion podems hacer:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;definimos la funcion:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;def hola(veces=1):&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;....&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;print("hola "* veces)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;ahora llamamos la funcion:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;hola()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;hola&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify; color: rgb(204, 204, 204);"&gt;como ven al tener un parametro opcional podemos llamar la funcion sin agumentos pero si queremos que me imprama dos veces el hola solo hay que colocar como argumento  el numero de veces que queramos que nos imprima el hola veamos:&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;hola(3)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;hola hola hola&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;bueno python trae una forma de declar muchos argumentos por defecto a traves de una&lt;a href="http://pycol.blogspot.com/2009/02/tuplas-en-python_27.html"&gt; tupla&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;veamos:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;def test(*tupla):&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;for val in tupla:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;                &lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;print(val)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Ahora si llamamos la funcion test() sin argumentos pues no va imprimir nada, pero si la llamamos con tres argumentos asi:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;test(1,2,3)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;2&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;3&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;tambien podemos hacer que de vez de una &lt;a href="http://pycol.blogspot.com/2009/02/tuplas-en-python_27.html"&gt;tupla &lt;/a&gt;sea un &lt;a href="http://pycol.blogspot.com/2009/03/diccionarios-en-python.html"&gt;diccionario,&lt;/a&gt; tan solo hay que hacer lo siguiente:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;def test(**diccionario):&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;for val in diccionario.items():&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;                &lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;print(val)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;ahora hacemos el llamado de esta forma:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;test(primero = 1)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;('primero', 1)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;aqui primero va ser de key del&lt;/span&gt;&lt;a href="http://pycol.blogspot.com/2009/03/diccionarios-en-python.html"&gt; diccionario&lt;/a&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;y 1 va hacer de value, :) bueno en Python tambien puedo llamar una funcion dentro de otra funcion veamos:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;def uno():&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;______&lt;/span&gt;print("Hola mundo")&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;def dos():&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;______&lt;/span&gt;uno()&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;dos()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;Hola mundo&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify; color: rgb(204, 204, 204);"&gt;Otro concepto de las funciones es cuando deciamos pasamos el argumento por valor o por referencia y algunos estaran diciendo y eso que ??&lt;br /&gt;Bueno cuando nosotros pasavamos un valor por referencia lo que realmente pasamos a la funcion es la direccion de memoria donde esta almacenada en contenido de la variable y esto lo hacemos cuando queremos que todo los cambios que realize nuestra funcio a dicha variable permanescan fuera de la funcion, cuando paso un argumento por valor lo que realmente hacemos es llevarnos una copia del contenido de nuestra variable y todos los cambios que se realizen dentro de la funcion solo permanece alla dentro de la funcion ya que las variables dentro de la funcion son locales, veamos un ejemplo para captar la idea:&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Bueno antes que nada hay que recordar que en Python todo es un objeto y que las listas son mutables los enteros y las tuplas inmutables ya que lo inmutable va atrabajar como paramatros por valor y lo mutable va ser paso por referencia:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;def f(x, y):&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;...&lt;/span&gt;____&lt;/span&gt;x = x + 3&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt; ...&lt;/span&gt;____&lt;/span&gt;y.append(2)&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;...&lt;/span&gt;____&lt;/span&gt;print x, y&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;x=7&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;y=[1]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;llamemos la funcion  y miremos que pasa:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;f(x,y)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;10 [1, 2]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Bueno ese resultado es del print dentro de la funcion la variable x que vale 7 le sume 3 ahi se refleja en el resultado 10, y a la lista le agrague un nuevo valor que es el dos, estos valores son los de la funcion ahora hagmos un print para ver que pasa ???&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt; print (x , y)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;7 [1, 2]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Como vemos fuera de la funcion el valor de la variables inmutables como la x se comporto como un paso por valor ya que dentro de la funcion tomo valor de 10 pero fuera de ella sigue valiendo 7, en cambio la &lt;a href="http://pycol.blogspot.com/2009/02/tuplas-en-python.html"&gt;lista &lt;/a&gt;que es mutable se comporto como un argumento por referencia ya que dentro de la funcion se le modifico añadiendo un nuevo elemento a la lista que fue el 2 y fuera de  la funcion aun permanece igual :) que bonito es entender un poquito dale si quedas aun con alguna duda me la haces saber :=)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Como mencione antes en Python solo existen funciones, nada de procedimientos ya que toda funcion Python simpre retorna algo, cuando no definimos el return python retorna none ah no me crees :( pues probemos  nada perdemos :) en la funcion anterior donde explique cuando para una funcion en Python en un parametro por valor y cuando es por referencia en dicha funcion no declare la el&lt;/span&gt;&lt;span style="color: rgb(255, 102, 0);"&gt; return&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;el cual es una palabra reservada por python para retornar un valor de una funcion&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;veamos:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;esta era nuestra funcion:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;def f(x, y):&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;...&lt;/span&gt;____&lt;/span&gt;x = x + 3&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt; ...&lt;/span&gt;____&lt;/span&gt;y.append(2)&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;...&lt;/span&gt;____&lt;/span&gt;print x, y&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;ahora hagan esto:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;z=f( 2,[5])&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;ahora imprimamos la variable z haber que tiene:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;print(z)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;None&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;hmm si ven  veamos como utilizar el return:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;def sumar(x, y):&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;..&lt;span style="color: rgb(0, 0, 0);"&gt;.______&lt;/span&gt;return x + y&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;br /&gt;&gt;&gt;&gt;print sumar(3, 2)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;5&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;asi de facil :) ahora que alguien me explique esto:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;def f(x, y):&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;...&lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;return x * 2, y * 2&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;br /&gt;&gt;&gt;&gt;a, b = f(1, 2)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Pues debe ser una trampa tuya verda??? como es que una funcion retorne dos valores imposible :( eso debe dar error, ejecutelo y te apuesto que python genera una excepcion, no ves que no ha generado nada verifica las variable a y b a=2 y b=4 , tonces como hace python??? bueno pues muy simple python sigue retornando solo un valor, lo que el hace internamente es crear una &lt;/span&gt;&lt;a style="color: rgb(204, 204, 204);" href="http://pycol.blogspot.com/2009/02/tuplas-en-python_27.html"&gt;tupla&lt;/a&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; con los valores de 2 y 4 y asi la funcion solo retorna una unica variable que es la tupla :)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Muy interesante, Python es una chimba :) &lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4666877516539627762-1558392413915837684?l=pycol.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pycol.blogspot.com/feeds/1558392413915837684/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://pycol.blogspot.com/2009/03/funciones-en-python.html#comment-form' title='1 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4666877516539627762/posts/default/1558392413915837684'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4666877516539627762/posts/default/1558392413915837684'/><link rel='alternate' type='text/html' href='http://pycol.blogspot.com/2009/03/funciones-en-python.html' title='FUNCIONES EN PYTHON'/><author><name>creamostuweb</name><uri>http://www.blogger.com/profile/05907170252728070066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_BXBLWp3PDyI/Sa7hI2snv9I/AAAAAAAAABo/t7ztseXzVjg/s72-c/principal' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4666877516539627762.post-827152057501178894</id><published>2009-03-02T13:46:00.016-05:00</published><updated>2009-03-12T18:55:46.323-05:00</updated><title type='text'>DICCIONARIOS EN PYTHON</title><content type='html'>&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Los Diccionarios tambien llamados matrices asociativas , ya que son colecciones que contiene &lt;span style="color: rgb(255, 102, 102);"&gt;clave:valor&lt;/span&gt; ejemplo:&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;diccionario = {"enero":1,"febrero":2,"marzo":3}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;diccionario&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;{'enero': 1, 'marzo': 3, 'febero': 2}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;En la parte de la clave podemos usar cualquier tipo de valor inmutable: numeros, candenas, booleanos o &lt;a href="http://pycol.blogspot.com/2009/02/tuplas-en-python_27.html"&gt;tuplas&lt;/a&gt; menos &lt;a href="http://pycol.blogspot.com/2009/02/tuplas-en-python.html"&gt;listas&lt;/a&gt; o diccionarios dado que son mutables. La difrencia que existe entre diccionarios con la listas o las tuplas es que los valores almacenados en el diccionario no se le accede a traves de su indice si no atraves de su clave utilizando el operador de [] asi que de esta forma nuestros diccionarios no tienen un orden prestablecido :|&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;diccionario["enero"]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;de esta misma manera podemos modificar valores&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;diccionario["enero"]=2&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;diccionario["enero"]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;lo dejamos como estaba&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;diccionario["enero"]=1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;diccionario["enero"]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;bueno en los diccionarios no se usa el&lt;/span&gt; &lt;a href="http://pycol.blogspot.com/2009/02/tuplas-en-python.html"&gt;slicing&lt;/a&gt;, &lt;span style="color: rgb(204, 204, 204);"&gt;entre otras cosa ya que los diccionarios no son secuencia, sino Mappings (mapeados, asociaciones)&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0); font-weight: bold;"&gt;FUNCIONES BASICAS :&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(255, 153, 0); font-weight: bold;"&gt;has_key(k) &lt;span style="color: rgb(204, 51, 204);"&gt;Comprueba si el diccionario tiene la clave k. Es equivalente a la sin-&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 51, 204);"&gt;&lt;span style="font-weight: bold;"&gt;taxis k in D.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;valido en python 2.x veamos:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;diccionario.has_key("enero")&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;True&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify; color: rgb(204, 204, 204);"&gt;si la clave enero se encuentra en nuestro diccionario nos devuelve True en caso contrario False, una equivalencia de esto seria:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt; "enero" in diccionario&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;True&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Debido a esta equivalencia este metodo se convertio en algo redundante producinedo una ambiguedad innecesaria, debido a esto la funcion &lt;span style="color: rgb(204, 204, 204);"&gt;D.has_key(k) fue eliminada de Python 3.x veamos:&lt;br /&gt;&lt;br /&gt;valido solo en python 3.x&lt;br /&gt;&lt;/span&gt; &lt;/div&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 51, 204);"&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt; "enero" in diccionario&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;True&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;ahora probemos la funcion has_key(k) en python 3.x&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;diccionario.has_key('febrero')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;Traceback (most recent call last):&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;  File "&lt;stdin&gt;", line 1, in &lt;module&gt;&lt;/module&gt;&lt;/stdin&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;AttributeError: 'dict' object has no attribute 'has_key'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;como podemos comprobar la funcion has_key fue eliminada de python 3.x pero de igual forma contamos con&lt;/span&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;"enero" in diccionario&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;para saber si se encuentra una clave de un diccionario :)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0); font-weight: bold;"&gt;&lt;br /&gt;get(k[, d])&lt;/span&gt; &lt;span style="color: rgb(204, 51, 204);"&gt;Busca el valor de la clave k en el diccionario. Es equivalente a utilizar D[k] pero al utilizar este método podemos indicar un valor a devolver por defecto si no se encuentra la clave, mientras que con la sintaxis D[k], de no existir la clave se lanzaría una excepción veamos:&lt;/span&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(204, 51, 204);"&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;diccionario.get("marzo")&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;3&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;esto tambien lo podiamos averiguar de la froma D[k]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;diccionario["marzo"]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;3&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;la ventaja de la funcion &lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 153, 0); font-weight: bold;"&gt;get(k[, d]) es que &lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;podemos indicar un valor a devolver si la clave no esta:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;diccionario.get("abril","valor no encontrado de la clave dada")&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;'valor no encontrado de la clave dada'&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;bueno ahi defini un mensaje personalizado pero puede ser tambien que devuelva un entero o una lista etc.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0); font-weight: bold;"&gt;items()&lt;/span&gt; &lt;span style="color: rgb(204, 51, 204);"&gt;Devuelve una lista de tuplas con pares clave-valor.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 102);"&gt;python 2.x&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&gt;&gt;&gt; diccionario.items()&lt;br /&gt;[('enero', 2), ('marzo', 3), ('febero', 2)]&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 102);"&gt;python 3.x&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;br /&gt;&gt;&gt;&gt; list[diccionario.items()]&lt;br /&gt;[('enero', 2), ('marzo', 3), ('febero', 2)]&lt;br /&gt;&lt;br /&gt;como ven el resutado devuelto es una&lt;a href="http://pycol.blogspot.com/2009/02/tuplas-en-python.html"&gt; lista&lt;/a&gt; [(clave:valor),......]&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;keys()&lt;/span&gt;&lt;span style="color: rgb(204, 51, 204);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(204, 51, 204);"&gt;Devuelve una&lt;a href="http://pycol.blogspot.com/2009/02/tuplas-en-python.html"&gt; lista&lt;/a&gt; de las claves del diccionario.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 102);"&gt;python 2.x&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&gt;&gt;&gt;diccionario.keys()&lt;br /&gt;['enero', 'marzo', 'febero']&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 102, 102);"&gt;python 3.x&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;list(diccionario.keys())&lt;br /&gt;['enero', 'marzo', 'febero']&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0); font-weight: bold;"&gt;values()&lt;/span&gt; &lt;span style="color: rgb(204, 51, 204);"&gt;Devuelve una &lt;a href="http://pycol.blogspot.com/2009/02/tuplas-en-python.html"&gt;lista&lt;/a&gt; de los valores del diccionario.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 102);"&gt;python 2.x&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt; diccionario.values()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;[2, 3, 2]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 102);"&gt;python 3.x&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(204, 51, 204);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt; list(diccionario.values())&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;[2, 3, 2]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(204, 51, 204);"&gt;&lt;span style="color: rgb(255, 153, 0); font-weight: bold;"&gt;pop(k[, d])&lt;/span&gt; Borra la clave k del diccionario y devuelve su valor. Si no se encuentra dicha clave se devuelve d si se especificó el parámetro o bien se lanza una excepción.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(204, 51, 204);"&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;equivalente tanto para python 2.x como 3.x&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt; diccionario.pop("enero")&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;2&lt;br /&gt;&gt;&gt;&gt;diccionario&lt;br /&gt;{'marzo': 3, 'febero': 2}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;tambien podemos hacer esto y es equivalentes tanto Python 2.x y 3.x:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;del diccionario ["marzo"]&lt;br /&gt;&gt;&gt;&gt;diccionario&lt;br /&gt;{'febero': 2}&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;si queremos eliminar todos los elemntod del dicionario tan solo hacemos:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;diccionario.clear()&lt;/span&gt;&lt;br /&gt;{ }&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(204, 51, 204);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;si se fijaron bien los metodos&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(255, 153, 0);"&gt;keys()&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;,&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(255, 153, 0);"&gt;values()&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;y&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(255, 153, 0);"&gt;items()&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;de un diccionario devolvían &lt;a href="http://pycol.blogspot.com/2009/02/tuplas-en-python.html"&gt;listas &lt;/a&gt;en &lt;span style="font-weight: bold;"&gt;key()&lt;/span&gt; devolvia una&lt;a href="http://pycol.blogspot.com/2009/02/tuplas-en-python.html"&gt; lista&lt;/a&gt; de las claves de un diccionario, de &lt;span style="font-weight: bold;"&gt;values() &lt;/span&gt;devolvia una &lt;a href="http://pycol.blogspot.com/2009/02/tuplas-en-python.html"&gt;lista&lt;/a&gt; de  los valores de un diccionario y&lt;span style="font-weight: bold;"&gt; items()&lt;/span&gt; devolvia una &lt;a href="http://pycol.blogspot.com/2009/02/tuplas-en-python.html"&gt;lista&lt;/a&gt; con clave:valor del diccionario osea el diccionario completo pero en una lista, cada una de esas funciones tiene una funcion analoga que serian:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(255, 153, 0);"&gt;keys()&lt;/span&gt;         &lt;span style="color: rgb(204, 204, 204);"&gt;analoga&lt;/span&gt;&lt;span style="color: rgb(255, 204, 204); font-weight: bold;"&gt; iter&lt;/span&gt;&lt;span style="color: rgb(255, 153, 0); font-weight: bold;"&gt;&lt;span style="color: rgb(255, 204, 204);"&gt;keys()&lt;/span&gt;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(255, 153, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(255, 153, 0);"&gt;values()&lt;/span&gt;     &lt;span style="color: rgb(204, 204, 204);"&gt;analoga&lt;/span&gt; &lt;span style="color: rgb(255, 204, 204);"&gt;iter&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(255, 204, 204);"&gt;values()&lt;/span&gt;      &lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 153, 0);"&gt;items()      &lt;/span&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;analoga&lt;/span&gt;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(255, 153, 0);"&gt; &lt;span style="color: rgb(255, 204, 204);"&gt;iter&lt;/span&gt;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(255, 204, 204);"&gt;items()&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;estas funciones analogas devuelven iteradores sobre la misma secuencia que las anteriores&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;, esto de los  iteradores lo explicare con mas detalle mas adelante.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;tambien se fijaron que en python 3.x hacemos en algunas funciones el llamados de list &lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(204, 51, 204);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;list(diccionario.values()) para imprimir los datos buen es que en python 3 se introduce un concepto llamado vista y vamos a tratar de ver las ventajas que trae esto contra versiones anteriores de python 3.x ya que cuando hacemos diccionario.keys() en python3  obtengo es la vista del diccionario&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;veamos:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 102);"&gt;python 3.x&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;d=diccionario.keys()        #obtengo la vista del diccionario&lt;br /&gt;&gt;&gt;&gt;type(v)&lt;br /&gt;class 'dict_keys'&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;como ves es de tipo&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;class 'dict_keys'&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt; iterador= iter(v)    &lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);" class="comment"&gt;# construyo un iterador a partir de la vista (no del dict!)&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt; keys = list(v)  &lt;span class="comment"&gt;# construyo una lista a partir de la vista&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;como ves es por eso que en python 3.x construimos la lista a partir de la vista si estamos en una version de python 2.x los iteradores lo conseguiamos de las funciones homologas (iterkeys(),iteritems() y itervalues() ) y en python 3.x  solo con la funcion iter&lt;/span&gt; &lt;span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;iterador= iter(v) &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;veamos con un ejemplo el concepto de vista para Python 3.x y su funcion iter() que su proposito puede ser mas para compatibilidad hacia atras con versiones previs a python 3.x&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;diccionario de ejemlo:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&gt;&gt;&gt;dic={"guido":"python","linus":"linux","richard":"gnu"}&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 102);"&gt;python 2.x&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;iterador=dic.iterkeys()&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;ahora borremos un elemento del diccionario:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;del(dic["linus"])&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;ahora iteramos:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;for key in iterador:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;....          print key&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;....&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;Traceback (most recent call last):&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;  File "&lt;stdin&gt;", line 1, in &lt;module&gt;&lt;/module&gt;&lt;/stdin&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;NameError: name 'iterador' is not defined&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;bueno nos genera un error ya que nuestro iterador tiene un diccionario definido y al modificarlo&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;ya no podemos iterarlo osea recorrerlo con el for :( y ahi es donde entra el concepto de vista con python3 porque las vista son iterables :) veamos:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 102);"&gt;python 3.x&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;dic={"guido":"python","linus":"linux","richard":"gnu"}&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;obtenemos la vista:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt; vista=dic.keys()&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;ahora borremos un elemento del diccionario&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(255, 102, 102);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;del(dic["linus"])&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(255, 102, 102);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;ahora iteramos con la vista:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;for key in vista:&lt;br /&gt;....          print (key)&lt;br /&gt;....&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;guido&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;richard&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(255, 102, 102);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;si en python 3.x hubieramos obtenido&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;el iterador atraves de la funcion iter() asi&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;iterador=iter(dic.keys()) si hacemos asi en python 3 tendriamos un comportamiento similar a Python 2.x y es el de que ese iterador no soporta modificacion durante la ejecucion&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Bueno creo que con lo que llevamos hasta aqui de python que son los tipos de datos operadores, listas, tuplas y diccionarios que era algo fundamental  antes de iniciar con funciones, sentencias condicionales y bucles, que lo veremos ya en el proximo post. vamos despacios porque con el lanzamiento de python3  en cada tema vamos mostrando como se hace en python 2.x y ahora como se hace en python 3.x bueno no es todo pero donde hallan cambios lo ire indicando para que los que andan practicando vean el porque de las excepciones que nos arroja, bueno cualquier duda me la hacen saber bye.&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(255, 102, 102);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Write By Hackchan&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4666877516539627762-827152057501178894?l=pycol.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pycol.blogspot.com/feeds/827152057501178894/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://pycol.blogspot.com/2009/03/diccionarios-en-python.html#comment-form' title='2 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4666877516539627762/posts/default/827152057501178894'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4666877516539627762/posts/default/827152057501178894'/><link rel='alternate' type='text/html' href='http://pycol.blogspot.com/2009/03/diccionarios-en-python.html' title='DICCIONARIOS EN PYTHON'/><author><name>creamostuweb</name><uri>http://www.blogger.com/profile/05907170252728070066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4666877516539627762.post-8345224431588442193</id><published>2009-02-27T12:24:00.000-05:00</published><updated>2009-02-27T12:53:33.353-05:00</updated><title type='text'>TUPLAS EN PYTHON</title><content type='html'>&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Todo lo que vimos en la seccion de&lt;/span&gt; &lt;a href="http://pycol.blogspot.com/2009/02/tuplas-en-python.html"&gt;LISTAS EN PYTHON&lt;/a&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;se aplica a las tuplas la unica diferencia que en vez de usa [ ] usamos ( ) bueno en realidad el operador que define la tupla solo es la , (coma)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;pero por claridad utilizamos el parentisis veamos:&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;t= (1,2,"hola",True)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;print(t)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;(1, 2, 'hola', True)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;igual seria tupla si la definimos sin el parentisis:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;t= 1,2,"hola",True&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;print(t)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt; (1, 2, 'hola', True)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;podemos verificar que es una tupla &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;type(t)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;class 'tuple'&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;listo creo que entendi voy a definir una tupla de un solo elemento para demostar que esto es refacil veamos:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&gt;&gt;&gt; tupla = 1&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;mi tupla de un elemento ;) veamos a ver si es verdad:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&gt;&gt;&gt;type(tupla)&lt;br /&gt;class 'int'&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Como ven tupla=1 es simplemente una asignacion de 1 a la variable tupla si hubieramos querido que fuera una tupla tan solo habia que hacer:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;br /&gt;&gt;&gt;&gt; tupla = 1 ,&lt;br /&gt;&gt;&gt;&gt;type(tupla)&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;class 'tuple'&lt;br /&gt;&gt;&gt;&gt;print(tupla)&lt;br /&gt;(1,)&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Bueno aqui tambien podemos usar el operador [ ] para referirnos a un elemento de la tupla digamos que aun tenemos esta tupla definida (1, 2, 'hola', True):&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;br /&gt;&gt;&gt;&gt;tupla[0]&lt;br /&gt;1&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;ahora tratemos de modificar el primer elemento de la tupla por cualquier otro valor a ver que pasa:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&gt;&gt;&gt;tupla[0]=12&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;Traceback (most recent call last):&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;  File "&lt;stdin&gt;", line 1, in &lt;module&gt;&lt;/module&gt;&lt;/stdin&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;TypeError: 'tuple' object does not support item assignment&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;genero un error, bueno esto se debe a que las tuplas son inmutables( esto quiere decir que una vez creada una tupla no se puede modificar) en cambio como vimos en el tema de las lista si se pueden modificar cuando sea, y ademas las lista cuenta con una serie de funciones utiles para su tratamiento, pero las tuplas tampoco posee esa serie de funciones :( tonoces para que carajo utilizo las tuplas para eso solo trabajo con lista, buena pregunta, solo te digo que la unica ventaja de las tuplas es que son mas ligeras que si vas a crear una lista que no va ser modificada osea de tamaño fijo mejor optas por una tuplas y asi ahorras memoria.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4666877516539627762-8345224431588442193?l=pycol.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pycol.blogspot.com/feeds/8345224431588442193/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://pycol.blogspot.com/2009/02/tuplas-en-python_27.html#comment-form' title='7 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4666877516539627762/posts/default/8345224431588442193'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4666877516539627762/posts/default/8345224431588442193'/><link rel='alternate' type='text/html' href='http://pycol.blogspot.com/2009/02/tuplas-en-python_27.html' title='TUPLAS EN PYTHON'/><author><name>creamostuweb</name><uri>http://www.blogger.com/profile/05907170252728070066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4666877516539627762.post-2883141787505053389</id><published>2009-02-26T23:44:00.000-05:00</published><updated>2009-02-27T11:07:11.475-05:00</updated><title type='text'>LISTAS EN PYTHON</title><content type='html'>&lt;style type="text/css"&gt;  &lt;!--   @page { size: 21cm 29.7cm; margin: 2cm }   P { margin-bottom: 0.21cm }  --&gt;  &lt;/style&gt;    &lt;p style="margin-bottom: 0cm; text-align: justify; color: rgb(204, 204, 204);"&gt;La lista es una colección de datos ordenada, alguna equivalencia con otros lenguajes seria los arrays o vectores. La lista puede contener cualquier tipo de dato (enteros, cadenas y otras listas ) veamos como se puede crear una lista:&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;lista = [''hola'',2,''hacker'',[1,2,3,4,5]]&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; text-align: justify; color: rgb(204, 204, 204);"&gt;si se dan cuenta nuestra lista principal tiene un string ''hola'', un entero 2 y otra lista, una lista dentro de otra lista :) esta definicion estan valida como para python 2.x y 3.x&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;print (lista)&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;['hola', 2, 'hacker', [1, 2, 3, 4, 5]]  &lt;/p&gt;  &lt;p style="margin-bottom: 0cm; text-align: justify; color: rgb(204, 204, 204);"&gt; bueno si queremos acceder a uno de los elementos de la lista lo hacemos utilizando el nombre que hacemos referencia a la lista en este caso lo llame lista puede ser cualquiera y entre corchete indicamos un indice, dicho indice va de 0 a n-1 veamos:&lt;/p&gt;  &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;print(lista[0])&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;hola&lt;/p&gt;  &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;print(lista[3])&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;[1, 2, 3, 4, 5]&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(204, 204, 204);"&gt;pero yo quiero es acceder al 2 pero,  no se que hago ya que es una lista dentro de otra veamos:&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;print(lista[3][1])&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;2&lt;/p&gt; &lt;p style="margin-bottom: 0cm; text-align: justify;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="text-align: justify; color: rgb(204, 204, 204);"&gt; &lt;/div&gt;&lt;p style="margin-bottom: 0cm; text-align: justify; color: rgb(204, 204, 204);"&gt;wow que bien esto de las tuplas esta muy bien, tenga en cuenta que este operador [] se puede utilizar para modificar los elementos de la lista de esta forma:&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;lista[0]=''Python''&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;print(lista)&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;['Phython', 2, 'hacker', [1, 2, 3, 4, 5]]  &lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; text-align: justify; color: rgb(204, 204, 204);"&gt; como vimos con el operador [ ] podemos hacer referencia a cualquier elemento de la lista de 0 a n-1 pero Python trae consigo algo que es recorrer la lista de ultimo al primero utilizando numeros negativos veamos:&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt; nombres = [''angelica'',''paola'',''hackchan'',''python'']&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;print (nombres[-1])&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;python&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;print (nombres[-4])&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;angelica&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; text-align: justify; color: rgb(204, 204, 204);"&gt;Para los curiosos que no tienen sentido comun ;) eso es bueno cuando se es ultra novatillo es que si haces referecia por ejemplo print(nombres[-5]) o print (nombres[4]) va generar un error que dice,  lista fuera de rango asi:&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(255, 0, 0);"&gt;Traceback (most recent call last):  &lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(255, 0, 0);"&gt;File "&lt;stdin&gt;", line 1, in &lt;module&gt;  &lt;/module&gt;&lt;/stdin&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(255, 0, 0);"&gt;IndexError: list index out of range  &lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; font-weight: bold; color: rgb(255, 153, 102);"&gt;SLICING O PARTICIONANDO:&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(204, 204, 204);"&gt;Este mecanismo nos permite seleccionar porciones de listas veamos:&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(204, 204, 204);"&gt;sigamos con esta lista&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt; nombres = [''angelica'',''paola'',''hackchan'',''python'']&lt;/p&gt;  &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;print(nombres[1:3])&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;['paola', 'hackchan']  &lt;/p&gt;  &lt;p style="margin-bottom: 0cm; text-align: justify; color: rgb(204, 204, 204);"&gt;Como vemos para indicar porciones de lista damos un numero inicial en donde quiero que inicie mi porcion seguido de (:) dos puntos y un numero final que me dice el limite de la lista OJO: ese numero final actua o me imprime el elemento de la lista contenida en  (numerofinal-1) por eso imprime hackchan y no Python, si queremos que vaya hasta python solo es:&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;print(nombres[1:4])&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;['paola', 'hackchan','python']&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(204, 204, 204);"&gt;definamos otra lista pero de solo enteros:&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt; n=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30]&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(204, 204, 204);"&gt;ahora vamos ver que si agregamos un tercer elemento inicio:fin:salto defino un salto para extraer los elementos de la lista:&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(204, 204, 204);"&gt;solo con (inicio:fin)&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;print(n[2:8])&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;[ 3, 4,  5,  6, 7, 8 ]&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(204, 204, 204);"&gt;ahora con (inicio:fin:salto)&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;print(n[2:8:2])&lt;/p&gt;  &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;[3, 5, 7 ]&lt;/p&gt; &lt;p style="margin-bottom: 0cm; text-align: justify;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt; &lt;/div&gt;&lt;p style="margin-bottom: 0cm; text-align: justify; color: rgb(204, 204, 204);"&gt;Como se dan cuenta con (inicio:fin:salto) lo primero que hace es obtener la lista definida en inicio:fin que en este caso al ser de 2:8 nos da [ 3, 4,  5,  6, 7, 8 ]  ahora el salto nos dice que sea de dos en dos por lo tanto solo va quedar [ 3, 5, 7 ] espero que me entiendan :) pues esta muy facil el concepto de como funciona, de todas maneras todos los temas los estoy explicando sin tecnisismo alguno salvo alguna definicion de un libro pero que luego ire explicando con mis palabras :) cualquier duda no se olviden comentar ya sea para aclarar algo o cerregirme vale sigamos.&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; font-weight: bold;"&gt; &lt;span style="color: rgb(51, 51, 255);"&gt;Extra:&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(204, 204, 204);"&gt;definimos una lista cualquiera o esta :)&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt; l=[''hackchan'',2,''python'',7]&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(204, 204, 204);"&gt;print(l[0:])&lt;span style="color: rgb(204, 51, 204);"&gt;  # imprime desde elemento 0 hasta ?? pues al no indicar nada python lo toma hasta el          &lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(204, 51, 204);"&gt;                   # ultimo&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;['hackchan', 2, 'python', 7]  &lt;/p&gt;  &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;print(l[2:])&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;[''python'', 7 ]&lt;/p&gt;    &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;print(l[:3])  &lt;/span&gt;&lt;span style="color: rgb(204, 51, 204);"&gt;#aqui al no indicar inicio pues Python lo toma desde 0&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;['hackchan', 2, 'python']  &lt;/p&gt;   &lt;p style="margin-bottom: 0cm; color: rgb(204, 204, 204);"&gt;Imprimo toda la lista una manera corta de hacerlo con el oerador [] :&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;print(l[:])  &lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;['hackchan', 2, 'python', 7]  &lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(204, 204, 204);"&gt;Indico que utlize toda la lista :: y luego a dicha lista muestre los elementos con un salto de dos en dos: &lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;print(l[::2])   &lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;['hackchan', 'python']&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(204, 204, 204);"&gt;tambien podemos modificar los elementos o la fraccion de lista que indicamos asi:&lt;/p&gt;  &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;l[0:2]=[3,4]&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(204, 204, 204);"&gt;ahora impriman la lista y veran lo que paso:&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;print(l)&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;[3, 4, 'python', 7]  &lt;/p&gt;     &lt;p style="margin-bottom: 0cm; text-align: justify; color: rgb(204, 204, 204);"&gt;Si ven cambiamos los dos primeros elementos de la lista y eso fue porque l[0:2]=[''hackchan'',2] pues eso son los dos elementos que vamos ha cambiar por [3, 4 ] :D bueno espero que me hayan entendido ;) bueno esto que hicimos es un manejo a pedal de manejar listas pues python tiene una serie de funciones para su tratamiento y que veremos a continuacion para no crear un enredo de temas luego :)&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(204, 204, 204);"&gt;veamos las sigiente funciones basicas para el manejo de listas:&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-weight: bold; color: rgb(255, 153, 0);"&gt;append(object) &lt;span style="color: rgb(204, 51, 204);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(204, 51, 204);"&gt;   Añade un objeto al final de la lista&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-bottom: 0cm; color: rgb(204, 204, 204);"&gt;digamos que tenemos:&lt;/p&gt;  &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;lista=[1,2,3,4,5,6,7]&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;lista.append(7)&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;print(lista)&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;[1, 2, 3, 4, 5, 6, 7, 7]&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="color: rgb(255, 153, 0); font-weight: bold;"&gt;count(value)&lt;/span&gt;       &lt;span style="color: rgb(204, 51, 204);"&gt;devuelve el numero de veces que se encontro value&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;lista.count(7)&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;2&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-weight: bold; color: rgb(255, 153, 0);"&gt;extend([iterable])&lt;/span&gt;   &lt;span style="color: rgb(204, 51, 204);"&gt;añada los elementos del iterable a la lista , hay que tener en cuenta que con el lo que hacemos es concatenar dos listas, haber veamos como funciona:&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;lista.extend([8])&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;[1, 2, 3, 4, 5, 6, 7, 7,8]&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;lista.extend([9,10,11,12,13])&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;[1, 2, 3, 4, 5, 6, 7, 7,8, 9, 10, 11, 12, 13 ]&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-weight: bold; color: rgb(255, 153, 0);"&gt;insert (index, object )&lt;/span&gt;&lt;span style="color: rgb(204, 51, 204);"&gt; inserta el objeto a la lista en la posiscion index veamos:&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;lista.insert(0,10)&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;print(lista)&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;[10, 1, 2, 3, 4, 5, 6, 7, 7,8, 9, 10, 11, 12, 13 ]&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt;   &lt;p style="margin-bottom: 0cm; text-align: justify; color: rgb(204, 204, 204);"&gt;&lt;span style="font-weight: bold; color: rgb(255, 153, 0);"&gt;index( value[, start [, stop ]] )&lt;/span&gt;  &lt;span style="color: rgb(204, 51, 204);"&gt;Devuelve la posicion que encontro la primera ocurrencia de value(ya que un valor de una lista puede estar repetido eje: [1,2,2,3] tonces si mando a pedir la posicion de 2 index me va a devolver el indice del primer 2 que encuentre en este caso el indice es 1, si se especifica start y stop que son opcionales indicamos el inicio y el fin de la sublista.&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;lista.index(10)&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;0&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(204, 204, 204);"&gt;como ves aun que tenemos dos 10 en la lista uno en la posicion 0 y el otro en la posicion 11 index me devuelve el indice de la primera coincidencia encontrada en la lista.&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-weight: bold; color: rgb(255, 153, 0);"&gt;pop(index) &lt;/span&gt;&lt;span style="color: rgb(204, 51, 204);"&gt;Devuelve el valor de la posicion index y lo elimina de la lista, si no se especifica la posicion, se utiliza el ultimo elemento de la lista  &lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;lista.pop(10)&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;9&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt; &lt;span style="color: rgb(192, 192, 192);"&gt;lo que hace pop es que elimina el elemento según el indice que le indique, como le pase el 10 ese indeice contiene el 9 lo muestra y queda eliminado&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;print(lista)&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;[10, 1, 2, 3, 4, 5, 6, 7, 7,8, 10, 11, 12, 13 ]&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(192, 192, 192);"&gt;si no indicamos indice a eliminar pues elimina el ultimo de la lista:&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;lista.pop()&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;13&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;print(lista)&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;[10, 1, 2, 3, 4, 5, 6, 7, 7,8, 10, 11, 12 ]  &lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="color: rgb(255, 153, 0); font-weight: bold;"&gt;remove(value)&lt;/span&gt;  &lt;span style="color: rgb(204, 51, 204);"&gt;eliminar la primera ocurrencia de value&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;lista.remove(7)&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;print(lista)&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;[10, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12]&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;lista.remove(10)&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;print(lista)&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;[1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12]&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;lista.remove(12)&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;print(lista)&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;[10, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11 ]&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt;  &lt;p style="margin-bottom: 0cm;"&gt;&lt;span style="font-weight: bold; color: rgb(255, 153, 0);"&gt;reverse()&lt;/span&gt;&lt;span style="color: rgb(204, 51, 204);"&gt; invierte la lista. Esta funcion trabaja sobre la propia lista dede la que se invoca el metodo, no sobre una copia.&lt;/span&gt;&lt;/p&gt;   &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;lista.reverse()&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;print(lista)&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;[11, 10, 8, 7, 6, 5, 4, 3, 2, 1] &lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(204, 204, 204);"&gt;para dejarla como estaba aplicamos otra ves reverse()&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;lista.reverse()&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;print(lista)&lt;/p&gt; &lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);"&gt;[1, 2, 3, 4, 5, 6, 7, 8, 10, 11]&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4666877516539627762-2883141787505053389?l=pycol.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pycol.blogspot.com/feeds/2883141787505053389/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://pycol.blogspot.com/2009/02/tuplas-en-python.html#comment-form' title='8 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4666877516539627762/posts/default/2883141787505053389'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4666877516539627762/posts/default/2883141787505053389'/><link rel='alternate' type='text/html' href='http://pycol.blogspot.com/2009/02/tuplas-en-python.html' title='LISTAS EN PYTHON'/><author><name>creamostuweb</name><uri>http://www.blogger.com/profile/05907170252728070066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4666877516539627762.post-1792161091211651063</id><published>2009-02-24T00:18:00.000-05:00</published><updated>2009-02-24T12:06:34.638-05:00</updated><title type='text'>EXPRESIONES Y SENTENCIAS EN PYTHON</title><content type='html'>&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Una expresion ???  bueno, es forma correcta de decirle o digitar mas bien  algo a nuestro interprete de manera que el interprete de Python me entienda y me conteste, aunque hay expresiones como en la vida real  que el interprete al igual que las personas se quedan sin palabras ;)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt; 1+1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;2&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; bueno aqui hay que saber que una variable y un valor se consideran expresiones&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;150&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;150&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;x=2&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;x&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;2&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;miren esto:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;mensaje="shalom"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;mensaje&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 255, 153);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;'shalom&lt;/span&gt;'&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 255, 153);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;print(mensaje)&lt;/span&gt; &lt;span style="color: rgb(204, 102, 204);"&gt;           #en python 2.x es print mensaje&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;shalom&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;ven la diferencia? Cuando Python muestra el valor de una expresion, muestra exactamente lo mismo que se digito al introducir el valor en el caso de dicha cadena 'shalom' la muestra tal y como fue asignada a la variable. Pero la sentencia print imprime el valor de la expresion en este caso el contenido de la cadena shalom. bueno esto se nota aqui con la cadenas :) si lo intentas con un entero pues no se va notar tanto esta diferencia :).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 153, 0);"&gt;OPERADORES Y EXPRESIONES&lt;/span&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Los operadores son pues unos simbolos especiales que varios de ellos lo vemos desde que tavamos bbs :) si esos que reprentas operaciones de calculo simples ya saben a cuales me refiero?? no son mas que las suma (+) la resta (-)  la division(/) y la multiplicacion(*) &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;veamos:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;20+32&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;52&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;hora=10&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;hora-1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;9&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;hora*60+2&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;602&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;5**2&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;25&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;(7-2)+(5*2-5)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;10&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;python 3.x&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;5/2&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;2.5&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;python 2.x&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;5/2&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;como ya sabran el simbolo (*) es el de la multiplicacion y el del (**) es el simbolo de la exponeciacion que falta de respeto hackchan :) pero los novatillos daran gracias al cielo por eso ;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;bueno deben saber que la expresion hora-1 donde, hora sera reemplazado por el valor que le asigne que en este caso fue 10 antes de hacer la operacion.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;como ven la suma,division,resta y la multiplicacion hacen lo que ya esperavamos que hicieran asi que no debe ser muy dificil para los totalmente novatos el captar estos conceptos, pero si le recuerdo que la division en python en su version 2.x no hace lo que uno quisiera qu haga ya que una division tan facil donde el resultado es 2.5 me arroja un 2 bueno en&lt;/span&gt; &lt;a href="http://pycol.blogspot.com/2009/02/variables-en-python.html"&gt;VARIABLEN CON PYTHON&lt;/a&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;ahi explique el porque de esa aparente anormalida con el resultado.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0); font-weight: bold;"&gt;El ORDEN DE LAS OPERACIONES:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Bueno los Ingleses (hello everybody) :D alguien quiere traducir este blog ??? jeje no que va ya hay bastantes en ingles :D bueno amigos portemonos serios ;) lo que venia diciendo es que hay un acronimo de los igleses que es&lt;/span&gt; &lt;span style="color: rgb(51, 102, 255);"&gt;PE&lt;span style="color: rgb(255, 102, 102);"&gt;MD&lt;/span&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;AS&lt;/span&gt;&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;algunos diran que rayos quiere decir bueno le voy a decir y no tienen que ir por el diccionario, buen&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;o se los digo a los que no saben que es un acronimo :)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;P&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt; arentisis   &lt;/span&gt;          &lt;span style="color: rgb(204, 204, 204);"&gt;(parentisis)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;E &lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; xponentiation &lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;  (Exponenciacion)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 102);"&gt;M&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;ultiplication&lt;/span&gt;       &lt;span style="color: rgb(204, 204, 204);"&gt; (Multiplicacion)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 102);"&gt;D&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;ivision  &lt;/span&gt;                &lt;span style="color: rgb(204, 204, 204);"&gt;(Division)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;A&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;ddition &lt;/span&gt;                &lt;span style="color: rgb(204, 204, 204);"&gt;(Adicion)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;S&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;ubtraction  &lt;/span&gt;         &lt;span style="color: rgb(204, 204, 204);"&gt;(Sustraccion)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Bueno el porque de esa clase de kindergarden, bueno solo es para recordarle las reglas de precedencia de estos simbolos y la campeona de todas osea la de mayor precedencia es el ()&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;veamos&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt; 2*3+2&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;8&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;pero si queremos que la suma se realize primero que la multiplicacion pues recurrimos  a los () que es el simbolo de mayor precedencia y por ende sera lo primero a realizar antes que nada veamos aver si es verda:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;2*(3+2)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;10&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;bueno el siguiente es la exponenciacion es la que sigue despues de () en tener la presedencia mas alta veamos:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&gt;&gt;&gt;5**2+1&lt;br /&gt;26&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;si ves, si te das cuenta ??? la exponenciacion al tener mayor precedencia que la suma se realiza primero 5 elevado ala dos y luego le sumo 1, oye pero quiero que la suma se haga primero que hago??? no mentiras es una broma :) ya me dijistes que el parentisis es el de mayor precedencia pues solo hay que hacer esto:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;5**(2+1)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;125&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;bueno los siguientes digo siguientes porque la multiplicacion y la division tienen el mismo nivel de precedencia claro esta que ambos estan por debajo de los parentesis y la &lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;exponenciacion&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; veamos:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;8*2/2&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;8&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;pero si hago lo invertido dara igual??? veamos&lt;/span&gt;:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;2/8*2&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;0.5            &lt;span style="color: rgb(255, 153, 255);"&gt; #los que usan pytho 2.x recuerden que el resultado va ser 0&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;si se dan cuenta?? esto es porque la division y la multiplicacion tienen el mismo nivel de presedencia entonces la expresion se evalua de izquierda a derecha.&lt;br /&gt;&lt;br /&gt;Bueno solo queda la adicion y la Sustraccion que son los de mas bajo nivel de precedencia y al igual que la multiplicacion y la division tambien comparten un mismo nivel de precedencia:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;1+2-8&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;-5&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;bueno vemos una serie de combinaciones:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;(25+3)/(1+3*2)*2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;bueno muchachos traten de hacer ese a mano y luego lo digitan en su interprete  Python no se hagan trampa que aqui venimos a equivocarnos y corregirnos para aprender :)  vamos cuanto nos dara esa expresion pues muy facil es 2 este cree que no me lei bien este post baboso, ole te pasastes :) dejame decirte que si te dio 2 estas remal, pero a los que le dio 2.3 esta muy mal tambien :( bueno quien da mas o menos :DDD bueno lo que dijeron menos le daria algo asi como 1.75 pero no,   no es la respuesta que busco, si ven y esta expresion es pequeñita y los que se equivocaron tienen que repasar y dejar esos conceptos claros ya que mas adelante veremos cuando tengamos que resolver algun ejercicio matematico tendremos expresiones realmente complejas:DD la respuesta era:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;(25+3)/(1+3*2)*2 &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;8&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;A los que antes de probarlo en su interprete Python los felicito van en busca del conocimiento y si les dio 8 es por que no son tan novatillos :DD bueno y los que hicieron trampa pues vamos esforcemonos mas la idea es aprender y a los hacker no me insulten no soy pedagogo y hay que enteder que ustedes en sus dias pasados fueron unos novatillos :) .  &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0); font-weight: bold;"&gt;LAS OPERACIONES CON CADENA&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Bueno en Python toda operacion matematica con una cadena es ilegal veamos:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;hola +2&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;Traceback (most recent call last):&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;  File "&lt;stdin&gt;", line 1, in &lt;module&gt;&lt;/module&gt;&lt;/stdin&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;TypeError: Can't convert 'int' object to str implicitly&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;asi que cualquier operacion basica (+ - * /) con cadenas (String) va generar el mismo error, creo que esto esta muy facil :) , pero que pasa si a dos String los tratamos de sumar veamos:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;"hola " + "Hackchan"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;hola hackchan&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;el operador (+) entre cadenas se utiliza para la concatenacion facil no??? sera que si nos ponemos de curioso haber que pasa si restamos (-) y dividimos (/) vale:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;"hola " - "Hackchan"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;Traceback (most recent call last):&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;  File "&lt;stdin&gt;", line 1, in &lt;module&gt;&lt;/module&gt;&lt;/stdin&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;TypeError: unsupported operand type(s) for -: 'str' and 'str'&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;"hola" / "Hackchan"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Traceback (most recent call last):&lt;br /&gt;File "&lt;stdin&gt;", line 1, in &lt;module&gt;&lt;br /&gt;TypeError: unsupported operand type(s) for /: 'str' and 'str'&lt;br /&gt;&lt;br /&gt;&lt;/module&gt;&lt;/stdin&gt;&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Bueno no sigamos siendo mas boludos probando lo inebitable ;) como ven el operador (+) se utliza&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;como en otros lenguages la concatenacion con este pequeño amigo, bueno el operador (*) tambien tiene un comportamiento algo muy interesante en cadenas para los que estan pensando en que "x"*"x" nos va dar "&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;x²&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;" pues creo que tienen una sobre dosis de numeros :) pues no esa no es la funcion del (*) vemos cual es:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt; "hola "*2+"hackchan"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;'hola hola hackchan'&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&gt;&gt;&gt; "g"+"o"*15+"l"&lt;br /&gt;'goooooooooooooool'&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0); font-weight: bold;"&gt;COMPOSICION:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Que hemos visto hasta aqui: las variables, las expresiones y las sentencias todo por separado bueno esperaba que ya lo fueran ustedes por su cuenta ir combinando todo lo que hemos visto vemos:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt; print (7 + 23)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;30&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Bueno en realida lo que hace el interprete Python es realizar primero la suma y luego llama la funcion print&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;hora = 2&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;minuto=&lt;/span&gt;&lt;/span&gt;4 &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51); font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt; print ("numero de minutos:",hora*60+minuto)  &lt;span style="color: rgb(255, 153, 255);"&gt;#si tienes python 2.x elimina los ( )&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;124&lt;br /&gt;&lt;br /&gt;&gt;&gt;&gt;porcentaje= (minuto * 100 ) / 60&lt;br /&gt;&gt;&gt;&gt;print(porcentaje)&lt;br /&gt;&gt;&gt;&gt; 6.66666666667&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Por ahora esta capacidad no es la gran cosa pero ya mas adelante veremos cosas mucho mas complejas con algo mas de breveda ;) para los novatillos y los no tan novatillos acuerdensen que la parte izquierda de una asignacion debe ser una variable:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;variable = minuto *100&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;ya que lo contrario seria totalmente ilegal:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;minuto*100 = variable&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;espero que esto sea de mas decirlo ya que me imagino que un ultranovatillo almenos sepa manejar el operador de asignacion ya que como vemos es ilogico decir 8= t a 8 asignarle t asi lo lee Python ya todo tiene un orden y una forma correcta recuerda que python es un lenguaje formal y las ambiguedades son solo para los lenguajes naturales ;).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 153, 0);"&gt;COMENTARIOS:&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Muchos ya sabemos esto y muchos no lo utilizamos creemos que nuestros programas  sera leidos sin problemas por otro programador tal vez eso sea asi pero te imaginas ponerser a entender y decifrar que hizo un programador a un programa realmente grande es mucho mas facil empezar de 0 que realizar el proceso de ingenieria inversa asi que una buena practica de programacion es que documente absolutamente todo mas adelante veremos un comentario especial que tiene Python para fines de la documentacion por ahora debemos saber que # todo lo que este despues de este simbolo python lo va ignorar ya que se trata de un comentario.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt; print 2 + 2  # suma de dos enteros&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;4&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;bueno todo lo que llevamos es algo muy basico que no esta de mas como es interpretado todo esto en Python tranquilos que ya llegaremos a explicar funciones y veremos el paradigma de la Programacion orientada a Objetos en python pero antes tendremos que ver que son listas tuplas y diccionarios hasta la proxima bye.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;write by Hackchan&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(255, 153, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4666877516539627762-1792161091211651063?l=pycol.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pycol.blogspot.com/feeds/1792161091211651063/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://pycol.blogspot.com/2009/02/expresiones-y-sentencias-en-python.html#comment-form' title='4 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4666877516539627762/posts/default/1792161091211651063'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4666877516539627762/posts/default/1792161091211651063'/><link rel='alternate' type='text/html' href='http://pycol.blogspot.com/2009/02/expresiones-y-sentencias-en-python.html' title='EXPRESIONES Y SENTENCIAS EN PYTHON'/><author><name>creamostuweb</name><uri>http://www.blogger.com/profile/05907170252728070066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4666877516539627762.post-8814579640360992452</id><published>2009-02-23T19:53:00.000-05:00</published><updated>2009-02-23T21:00:57.275-05:00</updated><title type='text'>VARIABLES EN PYTHON</title><content type='html'>&lt;div style="text-align: justify; color: rgb(204, 204, 204);"&gt;Las variables en Python tienen una longitud arbitraria. Pueden estar formadas por letras y numeros,pero deben comenzar con una letra o guion bajo. Debe tener mucho cuidado con la sensibilidad es decir no es lo mismo variable a Variable asi que por convencion es mejor evitar variables en mayusculas.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Los tipos de variables que Python maneja son:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Numerica&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;(entera,flotante,compleja)(12)(12.5)(6+3i)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;cadenas&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;(''hello world'')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;booleano&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;(True,False)(verdadero,Falso)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;De las siguientes variables cuales no son correctas??&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;&gt;&gt;&gt;77police=12&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;_km=77&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;&gt;&gt;&gt;$hack=”Hola Mundo”&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;&gt;&gt;&gt;cma$=66&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;clase=12&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;&gt;&gt;&gt;is=3&lt;/span&gt; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;&gt;&gt;&gt;class=”Curso de python”&lt;/span&gt; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify; color: rgb(204, 204, 204);"&gt;    las que estan mal son las rojas ;) , en la primera la variable inicia con un numero  esto no esta permitido en python.  Cualquier variable que contenga simbolos especiales como $ o cualquier otro como ()=?¿%$·”! no son permitidos en una variable y Python se va a quejar.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="text-align: justify; color: rgb(204, 204, 204);"&gt;&lt;div style="text-align: justify;"&gt;Ahora miremos is y class porque estan mal??? si cumple con la regla de variables de Python, estan mal porque son palabras reservadas de Python, pero que eso?? pues es una palabara que realizan algo especifico con un tratamiento especial otras palabras reservadas por Python son:&lt;br /&gt;&lt;span style="color: rgb(255, 255, 102);"&gt;(and,continue,else,elif,for,assert,break,def,except,exec,finally,from,global,if,import,in,lambda,not,or, pass,raice,return,try,while&lt;/span&gt;), ningunas de estas palabras pueden ser usadas como nombre de variables.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Como vemos el tipo de dato no lo definimos ya que Python es dinamico el internamente realiza esa operación por nosotros no es como en Java y C++ que son estaticos y a las variables hay que indicarle manualmente el tipo de dato:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;int v=12 # variable entera&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;long n=1500000 # variable entera grande&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;float z=12,3 #variable punto flotante&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;como vemos esta asigacion es totalmente estatica y Python realiza eso por nosotros, si queremos saber el tipo de dato de nuestra variable hacemos lo siguiente:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;tenemos&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;a=12&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;b=”hola mundo”&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;c=12.5&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;verificamos el tipo de las variables anteriores:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;type(a)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;type&gt;&lt;/type&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;type 'int'&lt;/span&gt;&lt;br /&gt;&lt;type style="color: rgb(51, 255, 51);" int=""&gt;&gt;&gt;&gt;type(b)&lt;br /&gt;&lt;/type&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;type&gt;&lt;/type&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;type 'str'&lt;/span&gt;&lt;br /&gt;&lt;type style="color: rgb(51, 255, 51);" int=""&gt;&lt;type str=""&gt;&gt;&gt;&gt;type(c)&lt;br /&gt;&lt;/type&gt;&lt;/type&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;type&gt;&lt;/type&gt;&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;type&gt;&lt;/type&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;type 'float'&lt;/span&gt;&lt;br /&gt;&lt;type int=""&gt;&lt;type str=""&gt;&lt;type float=""&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0); font-weight: bold;"&gt;ENTEROS:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;el rango de un entero en python -2.147.483.648 a 2.147.483.647 superando esto la variable automaticamente pasara hacer long&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;n=2147483647&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;type(n)&lt;/span&gt;&lt;br /&gt;&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;type&gt;&lt;/type&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;type 'int'&lt;/span&gt;&lt;br /&gt;&lt;type int=""&gt;&lt;type str=""&gt;&lt;type float=""&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;aumentamos en 1 la variable para sobrepasar el rango de enteros en 1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;entero=2147483648&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;type(n)&lt;/span&gt;&lt;br /&gt;&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;type&gt;&lt;/type&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;type 'long'&lt;/span&gt;&lt;br /&gt;&lt;type int=""&gt;&lt;type str=""&gt;&lt;type float=""&gt;&lt;br /&gt;&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;div style="text-align: justify;"&gt;&lt;type style="color: rgb(204, 204, 204);" int=""&gt;&lt;type str=""&gt;&lt;type float=""&gt;y vemos que nuestra variable paso hacer de tipo long podemos definir cualquier cantidad posible a una variable el unico limite es nuestra memoria ram :) entre mas ram, numeros extremadamente grandes podra almacenar una variable en Python.&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;br /&gt;&lt;type int=""&gt;&lt;type str=""&gt;&lt;type float=""&gt;&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;/div&gt;&lt;type int=""&gt;&lt;type str=""&gt;&lt;type float=""&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Podemos indicar que una variable entera Python la tome como long:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;n=21L #Puede ser l o L mayuscula&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;type(n)&lt;/span&gt;&lt;br /&gt;&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;type&gt;&lt;/type&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;type 'long'&lt;/span&gt;&lt;br /&gt;&lt;type int=""&gt;&lt;type str=""&gt;&lt;type float=""&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;podemos asinarle el valor a la variable de forma octal:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;n=027&lt;span style="color: rgb(204, 204, 204);"&gt; #anteponiendo el 0 (cero) indicamos que esta en modo octal que este caso es 23 en &lt;/span&gt;decimal&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;print n&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;23&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;podemos asignarle en forma Hexadecimal:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;n=0x17 &lt;span style="color: rgb(204, 204, 204);"&gt;#&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;anteponiendo el 0x: en este caso 0x17 equivale a 23 en decimal&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;ahora mira algo curioso en Python digamos que tengo una variable de esta forma&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;x=5&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;que pasa si hago:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;x=x/2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 255, 153);"&gt;2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;div style="text-align: justify; color: rgb(204, 204, 204);"&gt;&lt;type int=""&gt;&lt;type str=""&gt;&lt;type float=""&gt;???? por que carajo da 2 no deberia dar 2.5 a Python se le olvido dividir :) lo que pasa aquí es que si utilizamos dos operandos enteros Python determina que la variable resultado sea tambien un entero y por eso el resultado solo me devuelve la parte entera si queremos que nos devuelva el resultado como es debemos indicar un operando como real asi:&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;br /&gt;&lt;type int=""&gt;&lt;type str=""&gt;&lt;type float=""&gt;&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;/div&gt;&lt;type int=""&gt;&lt;type str=""&gt;&lt;type float=""&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;x=5.0&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;x=x/2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;2.5&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;o bien tambien podemos indicar el otro operando como real&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;x=5&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;x=x/2.0&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;2.5&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;otra solucion sera:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;x = float(5) / 2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;2.5&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0); font-weight: bold;"&gt;REALES:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;div style="text-align: justify;"&gt;&lt;type style="color: rgb(204, 204, 204);" int=""&gt;&lt;type str=""&gt;&lt;type float=""&gt;Bueno muchos ya conocen este tipo de dato que utilizamos en C++ o en Java en C++ tenieos el float y el Double que es igual al float pero con mayor precision en python siempre va ser de doble precision 1 bit para el signo, 11 para el exponente y 52 para la mantisa osea si mi matematicas a un no me falla para ir por la calculadora :D claro que mi Python es como una calculadora, miremos y vera que si :):&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;1+11+52&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;64&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;es un total de 64bits esto significa que los valores que podemos representar van desde ±2,2250738585072020 x 10-308 hasta&lt;br /&gt;±1,7976931348623157×10308.&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;br /&gt;&lt;type int=""&gt;&lt;type str=""&gt;&lt;type float=""&gt;&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;/div&gt;&lt;type int=""&gt;&lt;type str=""&gt;&lt;type float=""&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;r=0.77&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;n=0.00001&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;si les parece aburrido escribir 5 veces el 0 (cero) podemos hacer:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;n=0.1e4&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;div style="text-align: justify; color: rgb(204, 204, 204);"&gt;&lt;type int=""&gt;&lt;type str=""&gt;&lt;type float=""&gt;Hasta aquí todo bonito y facil pero esto es totalmente valido para las versiones de python inferior a su ultima version 3 que trae pequeños cambios en muchas cosas que para algunos programadores pusieron el grito en el cielo pero para otros lo ven como la evolucion del mismo lenguaje asi que miremos dichos cambios para este tema de las variables:&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;br /&gt;&lt;type int=""&gt;&lt;type str=""&gt;&lt;type float=""&gt;&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;/div&gt;&lt;type style="color: rgb(204, 204, 204);" int=""&gt;&lt;type str=""&gt;&lt;type float=""&gt;&lt;br /&gt;&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;div style="text-align: justify; color: rgb(204, 204, 204);"&gt;&lt;type int=""&gt;&lt;type str=""&gt;&lt;type float=""&gt;uno de los cambios es que el tipo entero y float se unificaron, solo va existir tipo entero, pero no te alarmes que a dicho entero le podas asignar la cifra que quieras bueno hasta donde aguante tu memoria Ram&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;br /&gt;&lt;type int=""&gt;&lt;type str=""&gt;&lt;type float=""&gt;&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;/div&gt;&lt;type int=""&gt;&lt;type str=""&gt;&lt;type float=""&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;veamos:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0); font-weight: bold;"&gt;Python 3.x&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt; n=10000000000000000000000000000&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;si estuvieramos en Python 2.x este tipo de variable seria un float pero vemos que tipo arroja&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;type(n)&lt;/span&gt;&lt;br /&gt;&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;class&gt;&lt;/class&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;type 'int'&lt;/span&gt;&lt;br /&gt;&lt;type int=""&gt;&lt;type str=""&gt;&lt;type float=""&gt;&lt;class int=""&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;vemos que si es verda :) unificaron el tipo de dato ahora solo existe int&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;se acuerdan de esto:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;x=5/2&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/class&gt;&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;div style="text-align: justify; color: rgb(204, 204, 204);"&gt;&lt;type int=""&gt;&lt;type str=""&gt;&lt;type float=""&gt;&lt;class int=""&gt;y que teniamos que hacer unos de los dos operadores reales o utilizar la funcion float para que nos arrojara el resultado de 2.5 pues en Python 3.x esto fue corregido veamos:&lt;/class&gt;&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;br /&gt;&lt;type int=""&gt;&lt;type str=""&gt;&lt;type float=""&gt;&lt;class int=""&gt;&lt;/class&gt;&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;/div&gt;&lt;type int=""&gt;&lt;type str=""&gt;&lt;type float=""&gt;&lt;class int=""&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;5/2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;2.5&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;“excelente” :)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;otro ejemplo:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;x= 6/5&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;print x&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;File "&lt;stdin&gt;&lt;/stdin&gt;&lt;/span&gt;&lt;stdin&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;", line 1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;print x&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;          ^&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;SyntaxError: invalid syntax&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/stdin&gt;&lt;/class&gt;&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;div style="text-align: justify; color: rgb(204, 204, 204);"&gt;&lt;type int=""&gt;&lt;type str=""&gt;&lt;type float=""&gt;&lt;class int=""&gt;&lt;stdin&gt;error pero que joda ahora que hice mal :( no lo que pasa es que hay que recordar que el tradicional print antes de python 3 era una palabra reservada y ahora se convirtio en una funcion asi que desde python 3.x debes hacer ahora:&lt;/stdin&gt;&lt;/class&gt;&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;br /&gt;&lt;type int=""&gt;&lt;type str=""&gt;&lt;type float=""&gt;&lt;class int=""&gt;&lt;stdin&gt;&lt;/stdin&gt;&lt;/class&gt;&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;/div&gt;&lt;type int=""&gt;&lt;type str=""&gt;&lt;type float=""&gt;&lt;class int=""&gt;&lt;stdin&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&gt;&gt;&gt;print(x)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;1.2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Ahora si bueno espero que no se desanimen porque el mundo necesita mas programadores en Python :) el tipo real permanece como lo vimos anteriormente.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/stdin&gt;&lt;/class&gt;&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;div style="text-align: justify;"&gt;&lt;type int=""&gt;&lt;type str=""&gt;&lt;type float=""&gt;&lt;class int=""&gt;&lt;stdin&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;bueno hasta aqui lo que tiene que ver con lo que son variables en python, cualquier error o aporte que nos ayuden para mejorar es bienvenido y no se le olviden que sus consejos y cualquier aporte que tenga que ver con Python es bienvenido y les recuerdo que al igual que ustedes estoy en el proceso de aprendisaje de Python :) bueno Animo que en unos dias estaremos haciendo aplicaciones y quien quita jueguitos 2d y en opengl :O asi que a estudiar y Programar bye.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;write by Hackchan&lt;/span&gt;&lt;br /&gt;&lt;/stdin&gt;&lt;/class&gt;&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;type int=""&gt;&lt;type str=""&gt;&lt;type float=""&gt;&lt;class int=""&gt;&lt;stdin&gt;&lt;/stdin&gt;&lt;/class&gt;&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;/div&gt;&lt;type int=""&gt;&lt;type str=""&gt;&lt;type float=""&gt;&lt;class int=""&gt;&lt;stdin&gt;&lt;br /&gt;&lt;br /&gt;&lt;/stdin&gt;&lt;/class&gt;&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4666877516539627762-8814579640360992452?l=pycol.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pycol.blogspot.com/feeds/8814579640360992452/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://pycol.blogspot.com/2009/02/variables-en-python.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4666877516539627762/posts/default/8814579640360992452'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4666877516539627762/posts/default/8814579640360992452'/><link rel='alternate' type='text/html' href='http://pycol.blogspot.com/2009/02/variables-en-python.html' title='VARIABLES EN PYTHON'/><author><name>creamostuweb</name><uri>http://www.blogger.com/profile/05907170252728070066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4666877516539627762.post-7057053846662419329</id><published>2009-02-22T13:17:00.003-05:00</published><updated>2009-03-05T11:06:46.861-05:00</updated><title type='text'>EL MUNDO PYTHON</title><content type='html'>&lt;div style="text-align: justify;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_BXBLWp3PDyI/SaGmO8_t52I/AAAAAAAAABg/8XF9PjS0DN0/s1600-h/python.jpg"&gt;&lt;img style="cursor: pointer; width: 370px; height: 124px;" src="http://4.bp.blogspot.com/_BXBLWp3PDyI/SaGmO8_t52I/AAAAAAAAABg/8XF9PjS0DN0/s400/python.jpg" alt="" id="BLOGGER_PHOTO_ID_5305704611840911202" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(204, 204, 204);font-family:arial;" &gt;Hola&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; a todos los programadores la idea principal de este blog es centrar todo lo que tiene que ver en el desarollo de aplicaciones con python. la duda de nuevos programadores es en que lenguaje inicio mi aprendisaje como programador???y los duros en java y .net no dan su brazo a torcer y los master en programacion web no les interesa porque para ellos no hay nada mejor para web sino php ...... pues en realidad python es como debio ser desde un princio Java bueno no voy a criticar a ninguno pues todos tienen ventajas y desventajas pero python promete mucho desde ya y para iniciadores en programacion es perfecto pues la escritura es elegante por obligacion mas no por convenciones ademas con python escribes aplicaciones de escritorio como web y son muy potentes no es por nada que Google esta reescribiendo su codigo a Python y no es por nada que contrataron a Guido el creador de Python para su desarollo y evolucion.en lo personal mis primeros pasos como estudiante fue C y C++ como todos sabemos C es el papa de de todo no habria windows ni Gnu-linux sin C porque en C++ serian mucho mas lento y en java un windows y un Gnu-linux serian desastrozos asi que por mi que todos estudieran C por aparte hasta convertirse es unos hacker de C ya con eso solo es estudiar las reglas del nuevo lenguaje aprender.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; Ademas python esta escrito en....... por supuesto con el "papa de los amores" :)  si C despues salte a java y por su puesto que java alivio la vida de los programadores pero a que precio??? :( y su&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; lucha por la multiplatoforma en aquellos dias mi maquina se recentia de mis programas con entorno grafico en java ya que lentitud de java en esos dias era muy notable con un equipito de ferreteria aun peor :D bueno dejemos el pasado y hablemos del futuro hablemos de Python en lo personal y por que aun en mi trabajos y mis aplicaciones aun no me ha tocado trabajar en Python pero no por eso no voy a dejar de ser parte hacia donde la programacion es cada vez mas cercana al lenguaje natural y por eso que todos los que van a ser participes de esta&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; aventura novatos y guru de este lenguaje aportemos todo nuestro conocimiento en fin de mejorar y ayudar a nuestra sociedad y que los grados de libertad de richard stallman esten simpre presentes en este blog bueno me queda no vas que decirle que igual que todos ustedes quiero convertirme en un guru de Python asi que a Programar&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;.&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;p style="margin-bottom: 0cm; color: rgb(255, 153, 0);" align="justify"&gt;&lt;span style="color: rgb(128, 128, 128);"&gt;&lt;b&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Características&lt;/span&gt;&lt;span style="color: rgb(255, 153, 0);"&gt; del lenguaje:&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;b&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Propósito general:&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Se pueden crear todo tipo de programas. No es un lenguaje creado específicamente para la web, aunque entre sus posibilidades sí se&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; encuentra el desarrollo de páginas.&lt;/span&gt;&lt;br /&gt;&lt;p style="margin-bottom: 0cm; color: rgb(255, 153, 0);" align="justify"&gt;&lt;span style="color: rgb(128, 128, 128);"&gt;&lt;b&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Multiplataforma&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0cm; color: rgb(204, 204, 204);" align="justify"&gt;Hay versiones disponibles de Python en muchos sistemas informáticos distintos. Originalmente se desarrolló para Unix, aunque cualquier sistema es compatible con el lenguaje siempre y&lt;span style="color: rgb(128, 128, 128);"&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;cuando exista un intérprete programado para él&lt;/span&gt;. &lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;b&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Interpretado&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;p style="margin-bottom: 0cm; color: rgb(204, 204, 204);" align="justify"&gt;&lt;span style="color: rgb(128, 128, 128);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Quiere decir que no se debe compilar el código antes de su ejecución. En realidad sí que se realiza una compilación, pero esta se realiza de manera transparente para el programador. En ciertos casos, cuando se ejecuta por primera vez un código, se producen unos bytecodes que se guardan en el sistema y que sirven para acelerar la compilación implícita que realiza el intérprete cada vez que se ejecuta el mismo código.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;b&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Interactivo&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;p style="margin-bottom: 0cm; color: rgb(0, 0, 0);" align="justify"&gt;&lt;span style="color: rgb(128, 128, 128);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Python dispone de un intérprete por línea de comandos en el que se pueden introducir sentencias. Cada sentencia se ejecuta y produce un resultado visible, que puede ayudarnos a entender mejor el lenguaje y probar los resultados de la ejecución de porciones de&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;código rápidamente.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;b style="color: rgb(255, 153, 0);"&gt;Orientado a Objetos&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0cm; color: rgb(0, 0, 0);" align="justify"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;La programación orientada a objetos está soportada en Python y ofrece en muchos casos una manera sencilla de crear programas con&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; componentes reutilizables.&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0cm; color: rgb(255, 153, 0);" align="justify"&gt;&lt;span style="color: rgb(128, 128, 128);"&gt;&lt;b&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Funciones y librerías&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;div style="text-align: justify; color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Dispone de muchas funciones incorporadas en el propio lenguaje, para el tratamiento de strings, números, archivos, etc. Además, existen muchas librerías que podemos importar en los programas para tratar temas específicos como la programación de ventanas o sistemas en red o cosas tan interesantes como crear archivos&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; comprimidos en .zip.&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;p style="margin-bottom: 0cm; color: rgb(255, 153, 0);" align="justify"&gt;&lt;span style="color: rgb(128, 128, 128);"&gt;&lt;b&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Sintaxis&lt;/span&gt; &lt;span style="color: rgb(255, 153, 0);"&gt;clara&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;div style="text-align: justify; color: rgb(204, 204, 204);"&gt;Por último, destacar que Python tiene una sintaxis muy visual, gracias a una notación identada (con márgenes) de obligado cumplimiento. En muchos lenguajes, para separar porciones de código, se utilizan elementos como las llaves o las palabras clave begin y end. Para separar las porciones de código en Python se debe tabular hacia dentro, colocando un margen al código que iría dentro de una función o un bucle. Esto ayuda a que todos los programadores adopten unas mismas notaciones y que los programas de cualquier persona&lt;span style="color: rgb(128, 128, 128);"&gt; tengan un aspecto muy similar.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Bueno&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; si quieres ver las organizaciones que usan Python vean en:&lt;/span&gt;&lt;br /&gt;&lt;a style="color: rgb(204, 51, 204);" href="http://wiki.python.org/moin/OrganizationsUsingPython"&gt;http://wiki.python.org/moin/OrganizationsUsingPython&lt;/a&gt;&lt;br /&gt;&lt;p style="margin-bottom: 0cm; color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(128, 128, 128);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Iniciemos entoces el mundo maravilloso de python con una comparacion de codigo entre C++ y Python de esa forma ir entendiendo esos cambios que nos podria confundir.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;nota:&lt;/span&gt; Python 3 no es compatible con versiones anteriores asi que a medida que vaya explicando los temas ire mostrando como se hacia en Python antes de la version 3 y sus cambios con referente a la nueva version, un cambio a tener presente desde ya es el print que en Python 2.x esra una palabra reservada (statement) con tratamiento especial y desde Python 3.x  es una funcion ahora hay que añadirle al tradicional print los parentisis pero esto no es problema al potencial poder que ahora tiene el print:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0); font-weight: bold;"&gt;Python 2.x&lt;/span&gt;&lt;br /&gt;-------------&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;print "Hola mundo"&lt;/span&gt;       #imprime y va a la linea&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;print "Hola mundo"&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;, &lt;/span&gt;     #imprime y no va a la linea&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0); font-weight: bold;"&gt;Python 3.x&lt;/span&gt;&lt;br /&gt;-------------&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;print ("Hola mundo")&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;print ("Hola mundo", end="")&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;p style="margin-bottom: 0cm; color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(255, 153, 0); font-weight: bold;"&gt;con C++&lt;/span&gt;&lt;span style="color: rgb(128, 128, 128);"&gt;&lt;b style="color: rgb(255, 153, 0); font-weight: bold;"&gt; seria:&lt;/b&gt;&lt;br /&gt;---------------&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 51);"&gt;void&lt;/span&gt;&lt;span style="color: rgb(255, 255, 51);"&gt; test(){&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 51);"&gt;int i=1;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 51);"&gt;while( i&amp;lt;11){&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 51);"&gt;printf("%d",i);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 51);"&gt;i++;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 51);"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="color: rgb(255, 255, 51);"&gt;printf("Fin...");&lt;/span&gt;&lt;br /&gt;&lt;p style="margin-bottom: 0cm; color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(128, 128, 128);"&gt;&lt;span style="color: rgb(255, 255, 51);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 51);"&gt;int&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 51);"&gt;main()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 51);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 51);"&gt;printf ("Numeros del 1 al 10&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 51);"&gt;\n");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 51);"&gt;test();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 51);"&gt;return 0;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 51);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0); font-weight: bold;"&gt;En&lt;/span&gt;&lt;span style="color: rgb(128, 128, 128);"&gt;&lt;b style="color: rgb(255, 153, 0); font-weight: bold;"&gt; Python:&lt;/b&gt;&lt;br /&gt;-------------&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="libre"&gt;&lt;span style="color: rgb(128, 128, 128);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;def test():&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="libre"&gt;&lt;span style="color: rgb(128, 128, 128);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;i = 1&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="libre"&gt;&lt;span style="color: rgb(128, 128, 128);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;while i &amp;lt;11:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class="libre"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;print (i)&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="libre"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;i += 1&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0cm; color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;print ("fin..")&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;def&lt;/span&gt;&lt;span style="color: rgb(128, 128, 128);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt; main():&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;print ("Numeros del 1 al 10")&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;test()&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;if__name__ == "__main__":main()&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Bueno el codigo en C++ no creo que haya que explicarlo o si ?????&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="margin-bottom: 0cm; color: rgb(204, 204, 204);" align="left"&gt;Explicacion&lt;span style="color: rgb(128, 128, 128);"&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;del codigo Python:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;def&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt; test():&lt;/span&gt;&lt;br /&gt;&lt;p style="margin-bottom: 0cm; text-align: justify; color: rgb(204, 204, 204);"&gt;aquí&lt;span style="color: rgb(128, 128, 128);"&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;solo estamos definiendo una &lt;a href="http://pycol.blogspot.com/2009/03/funciones-en-python.html"&gt;funcion&lt;/a&gt;, pero porque : y no { pues como python te exige a que escriba el codigo identado esto quiere decir que despues de los dos puntos tabules el contenido de la &lt;a href="http://pycol.blogspot.com/2009/03/funciones-en-python.html"&gt;funcion&lt;/a&gt;&lt;/span&gt;:&lt;/span&gt;&lt;/p&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;while i &amp;lt; 11:&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;print (i)&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;i += 1&lt;/span&gt;&lt;br /&gt;&lt;div style="text-align: justify; color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;como vemos print(i) y i+=1 esta aliniados a 4 espacios desde el while osea que todo las lineas que esten asi son las que el while va a reconocer como suyas, asi que como vemos ahora el print ( “fin..") sale de la sangria de 4 espacios y por ende es como decir un } cierre de ciclo.&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);" align="left"&gt;while&lt;span style="color: rgb(51, 255, 51);"&gt; i &amp;lt; 11:&lt;/span&gt;&lt;/p&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;           &lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;print (i)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;          &lt;span style="color: rgb(0, 0, 0);"&gt;____&lt;/span&gt;i+= 1&lt;/span&gt;&lt;br /&gt;&lt;p style="margin-bottom: 0cm; color: rgb(0, 0, 0);" align="justify"&gt;&lt;span style="color: rgb(128, 128, 128);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;print (" fin..") &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(128, 128, 128);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;aquí solo definimmos lo que va ser mi funcion principal no es necesario que se llame asi&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; pueden darle el nombre que quiera  "Viva los recuerdos de C" :)&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;br /&gt;&lt;br /&gt;def&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt; main():&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;imprimimos el mensaje y llamamos a nuestra &lt;a href="http://pycol.blogspot.com/2009/03/funciones-en-python.html"&gt;funcion&lt;/a&gt; test() la cual contiene&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; nuestro bucle.&lt;/span&gt;&lt;br /&gt;&lt;p style="margin-bottom: 0cm; color: rgb(0, 0, 0);" align="justify"&gt;&lt;span style="color: rgb(128, 128, 128);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;print ("Numeros del 1 al 10")&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;test()&lt;/span&gt;&lt;br /&gt;&lt;p style="margin-bottom: 0cm; color: rgb(204, 204, 204);" align="justify"&gt;&lt;span style="color: rgb(128, 128, 128);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;bueno la siguiente linea va asi por que si :) no mentiras, Para poder definir un modulo tanto como modulo como ejecutable se puede poner al final del modulo:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;if&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;__name__ == "__main__":main()&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify; color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;El interprete de Python reconoce el nombre del modulo cuando lo ejecutamos como "main" y ejecuta la &lt;a href="http://pycol.blogspot.com/2009/03/funciones-en-python.html"&gt;funcion&lt;/a&gt; main( ) (en este caso la llamamos asi puedes colocar el nombre que quieras) o cualquier serie de sentencias que pongamos.Sin embargo si solo importamos el módulo para usarlo en otro modulo el interprete, al no asignarle en __name__ el valor __main__ no ejecutará la &lt;a href="http://pycol.blogspot.com/2009/03/funciones-en-python.html"&gt;función&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);" align="justify"&gt;&lt;span style="color: rgb(128, 128, 128);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;main( ).&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;entendieron&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; ??? yo tampoco :) el tecnisismo es la barrera mas cruel entre el conocimiento y mi cerebro :)&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; haber esto es un truco de python para usar nuestro programa como un ejecutable por si solito o si las funciones que estan definidas es&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;este programa como test() al ser importado para reutilizar mi codigo entonces cuando hago esto miremoslo directamente desde el interprete&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;Python , digamos que&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;nuestro&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; archivito se llama conteo.py el obvio contiene el codigo anterior de&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; Python&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);" align="justify"&gt;&amp;gt;&amp;gt;&amp;gt;import&lt;span style="color: rgb(128, 128, 128);"&gt; &lt;span style="color: rgb(51, 255, 51);"&gt;conteo&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&amp;gt;&amp;gt;&amp;gt;conteo.test()&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;br /&gt;1&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;br /&gt;2&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;br /&gt;3&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;br /&gt;4&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;br /&gt;5&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;br /&gt;6&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;br /&gt;7&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;br /&gt;8&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;9&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&lt;br /&gt;10&lt;/span&gt;&lt;br /&gt;&lt;p style="margin-bottom: 0cm; color: rgb(0, 0, 0);" align="justify"&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;vas&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; captando el uso de este truco if __name__ == "__main__":main() nuestro archivo conteo.py&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;puede&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; ser llamado por si solo o desde un import para usar las funciones que esten definidas alli &lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;y&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; cunado hacemos import conteo el ignora main().&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; Algo&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; muy importante ha tener en cuenta cuando hacemos import los archivos son buscados en unas rutas definidas por Python si queremos ver&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;cuales son esas rutas basta con hacer lo siguiente:&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&amp;gt;&amp;gt;&amp;gt;import&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);"&gt; sys&lt;/span&gt;&lt;br /&gt;&lt;p style="margin-bottom: 0cm; color: rgb(51, 255, 51);" align="justify"&gt;&lt;span style="color: rgb(128, 128, 128);"&gt;&lt;span style="color: rgb(51, 255, 51);"&gt;&amp;gt;&amp;gt;&amp;gt;sys.path&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;este&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; es el resultado en mi compu con ubuntu 8.10:&lt;/span&gt;&lt;br /&gt;&lt;p style="margin-bottom: 0cm; text-align: justify; color: rgb(204, 204, 204);"&gt;&lt;span style="color: rgb(128, 128, 128);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;['','/usr/lib/python2.5', '/usr/lib/python2.5/plat-linux2','/usr/lib/python2.5/lib-tk',/usr/lib/python2.5/&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;lib-dynload',&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;'/usr/local/lib/python2.5/site-packages','/usr/lib/python2.5/site packages',&lt;/span&gt;'/usr/lib/python2.5/site-packages/Numeric',&lt;span style="color: rgb(204, 204, 204);"&gt;'/usr/lib/python2.5/site-packages/PIL &lt;/span&gt;'/usr/lib/python2.5/site-packages/gst-0.10',&lt;span style="color: rgb(128, 128, 128);"&gt;'&lt;span style="color: rgb(204, 204, 204);"&gt;/var/lib/python-support/python2.5',&lt;/span&gt;&lt;/span&gt;/usr/lib /python2.5/site-packages/gtk-2.0',&lt;span style="color: rgb(204, 204, 204);"&gt;'/var/lib/python-support/python2.5/gtk-2.0',&lt;/span&gt;&lt;span style="color: rgb(128, 128, 128);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;'/usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode'] &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;como vemos son varias rutas donde Python busca los archivos, claro esta que podemos definir nuestra propia ruta pero de apocos :) mientras el archivo conteo.py lo podes copiar ha /usr/lib/python2.5 solo te ubicas donde esta nuestro archivo conteo.py y hacemos sudo cp conteo.py&lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt;/usr/lib/python2.5&lt;/span&gt;&lt;br /&gt;&lt;p style="margin-bottom: 0cm; color: rgb(0, 0, 0);" align="justify"&gt;&lt;br /&gt;&lt;/p&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Asi&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; que si python se quejo de esta forma:&lt;/span&gt;&lt;br /&gt;&lt;p style="margin-bottom: 0cm; color: rgb(255, 0, 0);" align="justify"&gt;Traceback&lt;span style="color: rgb(128, 128, 128);"&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;(most recent call last):&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;File "&amp;lt;stdin&amp;gt;", line 1, in &amp;lt;module&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;ImportError:&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;&lt;br /&gt;No module named hack.py&lt;/span&gt;&lt;br /&gt;&lt;p style="margin-bottom: 0cm; color: rgb(0, 0, 0);" align="justify"&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;es&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; porque cuando haces el import nuestro programa no esta almacenado en una de las rutas especificas para tal fin.&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; Este comienzo para muchos puede ser traumatico pero maneja programacion&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; muy basica para ver &lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;la&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; diferencia desde lo que nos interesa a todos en la proxima veremos los que son &lt;a href="http://pycol.blogspot.com/2009/02/tuplas-en-python.html"&gt;Listas&lt;/a&gt;, &lt;a href="http://pycol.blogspot.com/2009/02/tuplas-en-python_27.html"&gt;tuplas &lt;/a&gt;y &lt;a href="http://pycol.blogspot.com/2009/03/diccionarios-en-python.html"&gt;diccionarios&lt;/a&gt; para luego entrar a ver sentencias condicionales y control de flujo.&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;compilar en linux:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;p style="margin-bottom: 0cm; color: rgb(204, 204, 204);" align="justify"&gt;&lt;span style="color: rgb(128, 128, 128);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;cualquier distro de linux ya viene con el compilador de Python&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;1)cualquier&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; editor de texto nos sirve para escribir en Python&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;2)todos&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; los archivos con codigo Python debe tener la extension .py&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;3)para hacer que nuestro archivo sea ejecutable la primera linea de nuestro&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; archivo debe ser&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; #!/usr/bin/env python&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;4)damos&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; permisos de ejecucion # sudo chmod 755 miprograma.py&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;5)&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;lo ejecutamos ./miprograma.py&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;6)tambien de forma directa podemos hacer python miprograma.py y si es&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; con python 3 pues solo hacemos python3 miprogra.py&lt;/span&gt;&lt;br /&gt;&lt;p style="margin-bottom: 0cm; color: rgb(0, 0, 0);" align="justify"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Para&lt;/span&gt;&lt;span style="color: rgb(128, 128, 128);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt; nuestros windowseros desde aquí:&lt;/span&gt;&lt;br /&gt;&lt;a style="color: rgb(204, 51, 204);" href="http://www.python.org/download/releases/3.0.1/"&gt;http://www.python.org/download/releases/3.0.1/&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="margin-bottom: 0cm; color: rgb(0, 0, 0);" align="justify"&gt;&lt;span style="color: rgb(128, 128, 128);"&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;esta es la ultima version disponible desde e&lt;/span&gt;l &lt;span style="color: rgb(255, 102, 102);"&gt;13 de De Feb. Del 2009&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0cm; color: rgb(0, 0, 0);" align="justify"&gt;&lt;br /&gt;&lt;span style="color: rgb(128, 128, 128);"&gt;&lt;span style="color: rgb(255, 102, 102);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-bottom: 0cm; color: rgb(0, 0, 0);" align="justify"&gt;&lt;span style="color: rgb(128, 128, 128);"&gt;&lt;span style="color: rgb(255, 102, 102);"&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;write by Hackhan&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4666877516539627762-7057053846662419329?l=pycol.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pycol.blogspot.com/feeds/7057053846662419329/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://pycol.blogspot.com/2009/02/hola-todos-los-programadores-la-idea_22.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4666877516539627762/posts/default/7057053846662419329'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4666877516539627762/posts/default/7057053846662419329'/><link rel='alternate' type='text/html' href='http://pycol.blogspot.com/2009/02/hola-todos-los-programadores-la-idea_22.html' title='EL MUNDO PYTHON'/><author><name>creamostuweb</name><uri>http://www.blogger.com/profile/05907170252728070066</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_BXBLWp3PDyI/SaGmO8_t52I/AAAAAAAAABg/8XF9PjS0DN0/s72-c/python.jpg' height='72' width='72'/><thr:total>0</thr:total></entry></feed>
