Skip to content

Commit b9b3cdf

Browse files
committed
#2-python
1 parent 946ba8b commit b9b3cdf

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#funciones basicas
2+
3+
#simples
4+
def saludar():
5+
print("Hola Python")
6+
7+
saludar()
8+
9+
#retorno
10+
def funcion_de_retorno():
11+
return "retorno de funcion"
12+
13+
print(funcion_de_retorno())
14+
15+
#con argumento
16+
17+
def saludo_de_cumpleaños(años, nombre):
18+
print(f"felicidades por tus {años} años {nombre}")
19+
20+
saludo_de_cumpleaños(33, "mateo")
21+
22+
23+
#con un argumento predeterminado
24+
def saludo_de_cumpleaños_predeterminado(años, nombre="crack!"):
25+
print(f"felicidades por tus {años} años {nombre}")
26+
27+
saludo_de_cumpleaños_predeterminado(33)
28+
29+
30+
#con retorno de varios valores
31+
32+
def retorno_multiple():
33+
return "Hola","Maxi"
34+
35+
saludo, nombre = retorno_multiple()
36+
print(saludo)
37+
print(nombre)
38+
39+
#funciones con numero variable de argumentos
40+
41+
def argumentos_multiples_variables(*names):
42+
for name in names:
43+
print(f"Hola, {name}!")
44+
45+
46+
argumentos_multiples_variables("Nicolás", "Maxi", "Pepe", "Lorena", "Melani")
47+
48+
49+
#con numero variable de argumentos con palabra clave
50+
51+
def argumentos_multiples_variables(**names):
52+
for key, value in names.items():
53+
print(f"{value} ({key})!")
54+
55+
56+
argumentos_multiples_variables(
57+
name = "Nicolás",
58+
edad = 32,
59+
idioma = "español",
60+
nacionalidad = "uruguayo",
61+
)
62+
63+
64+
65+
66+
67+
#FUNCIONES DENTRO DE FUNCIONES
68+
69+
def funcion_contenedora():
70+
def funcion_contenida():
71+
print("soy una funcion interna")
72+
funcion_contenida()
73+
74+
funcion_contenedora()
75+
76+
77+
#FUNCIONES YA CREADAS EN PYTHON
78+
79+
print(len("Nicolás Heguaburu"))
80+
print(type(32))
81+
print("nico".upper())
82+
83+
84+
# Variables locales y globales
85+
86+
global_var = "python"
87+
88+
print(global_var)
89+
90+
def hola_python():
91+
local_var = "hola" #solo la puedo llamar en la funcion hola_python()
92+
print(f"Hola {global_var}")
93+
94+
hola_python()
95+
96+
97+
98+
#EJERCICIO EXTRA
99+
100+
def mi_funcion (str1, str2):
101+
num = 0
102+
for i in range(1, 101):
103+
if i % 3 == 0 and i % 5 == 0:
104+
print(f"{str1} y {str2}")
105+
elif i % 3 == 0:
106+
print(str1)
107+
elif i % 5 == 0:
108+
print(str2)
109+
else:
110+
print(i)
111+
num += 1
112+
return num
113+
114+
115+
116+
print(mi_funcion("soy multiplo de 3", "soy multiplo de 5"))
117+

0 commit comments

Comments
 (0)