Skip to content

Commit 63b35a7

Browse files
author
Alexander Carreno
committed
#2 - Python
1 parent 1b675d8 commit 63b35a7

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
"""
2+
* Funciones
3+
"""
4+
5+
# Simple
6+
7+
def language():
8+
print("Python")
9+
10+
language()
11+
12+
# Con retorno
13+
14+
def return_language():
15+
return "Python"
16+
17+
print(return_language())
18+
19+
# Con multiples retornos
20+
21+
def multiple_return_language():
22+
return "This is", "Python"
23+
24+
text, language = multiple_return_language()
25+
26+
print(text)
27+
print(language)
28+
29+
# Con un argumento
30+
31+
def argument_language(language):
32+
print("The language is", language)
33+
34+
argument_language("Python")
35+
36+
# Con varios argumentos
37+
38+
def arguments_language(language, version):
39+
print(f"The language is {language} and the version is {version}")
40+
41+
arguments_language("Python", "3.12.3")
42+
43+
# Con un argumento predeterminado
44+
45+
def default_argument_language(language="not JavaScript"):
46+
print("The language is", language)
47+
48+
default_argument_language() # JavaScript
49+
default_argument_language("Python")
50+
51+
# Con argumentos posicionales
52+
53+
def positional_arguments_language(language, version):
54+
print(f"The language is {language} and the version is {version}")
55+
56+
positional_arguments_language(version="3.12.3", language="Python")
57+
58+
# Con un numero de variables de argumentos (args)
59+
60+
def args_language(*languages):
61+
for language in languages:
62+
print(language)
63+
64+
args_language("Python", "JavaScript", "TypeScript")
65+
66+
# Con un nuemero de argumentos de palabras clave (kwargs)
67+
68+
def kwargs_language(**languages):
69+
for key, value in languages.items():
70+
print(f"{key}: {value}")
71+
72+
kwargs_language(language_1="Python", language_2="JavaScript", language_3="TypeScript")
73+
74+
# * Funciones dentro de funciones
75+
76+
def other_function():
77+
def inside_function():
78+
print("Inside function")
79+
80+
inside_function()
81+
82+
other_function()
83+
84+
# * Algunas funciones ya creadas del lenguaje
85+
86+
print("Hello")
87+
print(type("Hello"))
88+
print(len("Hello"))
89+
print("Hello".upper())
90+
print("Hello".find("o"))
91+
92+
# * Variable LOCAL y GLOBAL
93+
94+
global_variable = "Variable global"
95+
96+
def scope():
97+
local_variable = "Variable local"
98+
print(f"{local_variable} and {global_variable}")
99+
100+
print(global_variable)
101+
# print(local_variable) # Error es local, no se puede acceder
102+
103+
scope()
104+
105+
"""
106+
* Extra
107+
"""
108+
109+
def extra(text_1, text_2):
110+
count = 0
111+
for number in range(1, 101):
112+
if number %3 == 0 and number %5 == 0:
113+
print(text_1, text_2)
114+
elif number %3 == 0:
115+
print(text_1)
116+
elif number %5 == 0:
117+
print(text_2)
118+
else:
119+
print(number)
120+
count += 1
121+
return count
122+
123+
print(extra("Language", "Python"))

0 commit comments

Comments
 (0)