This repository has been archived by the owner on Jan 3, 2024. It is now read-only.
forked from mouredev/retos-programacion-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mouredev.py
76 lines (59 loc) · 1.61 KB
/
mouredev.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Hola mundo
print("¡Hola, Python!")
# Variables
my_variable = "Esto es una variable"
my_variable = "Aquí asigno un nuevo valor a la variables"
# Tipos de datos primitivos
my_string: str = "Mi cadena de texto"
my_int: int = 1
my_float: float = 1.5
my_bool: bool = True
# Constantes
MY_CONSTANT = "No existen las constantes. Simplemente se nombran variables en mayúscula."
# Control de flujo
if my_int == 1:
print("my_int vale 1")
elif my_int == 2:
print("my_int vale 2")
else:
print("my_int no vale ni 1 ni 2")
# Estructuras
my_list: list = [my_string, my_int, my_float, my_bool]
my_tuple: tuple = (my_string, my_int, my_float, my_bool)
my_set: set = set([my_string, my_int, my_float, my_bool, my_string])
my_dictionary: dict = {"str": my_string, "int": my_int, "float": my_float, "bool": my_bool}
# Bucles
for index in range(10):
print(index)
for item in my_list:
print(item)
index = 0
while index < len(my_list):
print(my_list[index])
index += 1
# Funciones
def my_function():
print("Función simple")
def my_function_with_return() -> str:
return "Función con retorno"
def my_function_with_parm(param: int):
print(f"Función con un parámetro de valor {param}")
my_function()
print(my_function_with_return())
my_function_with_parm(256)
# Clases
class MyClass():
def __init__(self, name):
self.name = name
def hello(self):
print(f"¡Hola, {self.name}!")
my_class = MyClass("MoureDev")
print(my_class.name)
my_class.hello()
# Excepciones
try:
print(0 / 0)
except:
print("Se ha producido una excepción")
finally:
print("Siempre se ejecuta el finally")