This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| # -*- coding: utf-8 -*- | |
| class cuenta_bancaria(): | |
| def __init__(self): | |
| self.titular = "Fulano" | |
| self.num_cuenta = "123456789" | |
| self.saldo = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| #coding: utf-8 | |
| # Nota que, en el valor que recibe la función, tiene 'cancion="lalala"' | |
| # Canción es la variable, como siempre, y "lalala" es lo que se le asignará por defecto si no se le pasa ningún valor | |
| def canta(cancion="lalala"): | |
| if cancion == "lalala": | |
| print "Laaa, lala laaa, lala laaa, lala laaaaaaa..." | |
| elif cancion == "himno": |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| #coding: utf-8 | |
| def valora(entrada): | |
| """ | |
| Evalua aserciones lógicas en función de parámetros fundamentales | |
| e interpreta su contenido para emitir un juicio valorativo. | |
| El tiempo de proceso es independiente de la longitud de la entrada. | |
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| #coding: utf-8 | |
| # Ejemplo de herencia. | |
| class Mamifero(): | |
| def __init__(self): | |
| descrpcion= "Los mamíferos son interesantes" | |
| def tiene_pelo(self): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| #coding: utf-8 | |
| # Ejemplo de clase. | |
| class Acuario(): | |
| #El método __init__ se ejecuta automáticamente al llamar a la clase | |
| def __init__(self, litros, tipo, num): | |
| self.capacidad = litros |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if expresion_a_evaluar: | |
| ejecutar_si_cierto |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if expresion_a_evaluar: | |
| ejecutar_si_cierto | |
| else: | |
| ejecutar_en_caso_contrario |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if expresion_a_evaluar_1: | |
| ejecutar_si_cierto_1 | |
| elif expresion_a_evaluar_2: | |
| ejecutar_si_cierto_2 | |
| elif expresion_a_evaluar_3: | |
| ejecutar_si_cierto_3 | |
| else: | |
| ejecutar_si_ninguna |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if x > 10: | |
| print "La variable es mayor que diez" | |
| elif x < 10: | |
| print "La variable es menor que diez" | |
| else: | |
| print "La variable es, precisamente, diez" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| while condicion: | |
| instruccion_a_ejecutar |