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
# Ejercicio 418: Agregar un nuevo elemento a un objeto tupla. | |
numeros = (1, 2, 3, 4) | |
print(len(numeros)) | |
print(numeros) | |
print() | |
numeros_nuevo = numeros + (5,) |
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
# Ejercicio 417: Desempaquetar los elementos de una tupla en diferentes variables. | |
punto_3d = (2, 3, 5) | |
print(punto_3d) | |
print(len(punto_3d)) | |
x, y, z = punto_3d | |
print(x, y, z) |
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
# Ejercicio 416: Iterar el contenido de una tupla a través de un ciclo while. | |
numeros = (2, 3, 5, 7, 11, 13, 17, 19) | |
i = 0 | |
while i < len(numeros): | |
print(numeros[i]) | |
i += 1 |
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
# Ejercicio 415: Iterar el contenido de una tupla a través de un ciclo for. | |
numeros = (2, 3, 5, 7, 11, 13, 17, 19) | |
for i in range(len(numeros)): | |
print(numeros[i]) | |
print() | |
for n in numeros: |
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
# Ejercicio 414: Modificar el contenido de una tupla (TypeError). | |
punto = (2, 3) | |
print(punto) | |
print(len(punto)) | |
# punto[0] = 5 # TypeError | |
# print(punto) |
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
# Ejercicio 413: Acceder al contenido de un objeto tupla. | |
punto = (2, 3) | |
print(punto) | |
print('Primer elemento de la tupla: {}'.format(punto[0])) | |
print('Segundo elemento de la tupla: {}'.format(punto[1])) | |
print() |
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
# Ejercicio 412: Crear un objeto tupla con un único elemento. | |
tupla = (2,) | |
print(tupla) | |
print(type(tupla)) |
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
# Ejercicio 411: Omitir los paréntesis al momento de crear un objeto de tipo tupla. | |
def fn(): | |
a = 1 | |
b = 2 | |
return a, b | |
tupla_1 = (1, 2, 3) |
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
# Ejercicio 410: Crear una tupla con elementos de diferente tipo de dato. | |
persona = ('Daniela', 'Ortiz', 29, '[email protected]', True, 100000.50) | |
print(persona) |
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
# Ejercicio 408: Crear un objeto tupla vacía con una literal y la clase tuple. | |
# literal tupla vacía: | |
t = () | |
print(type(t)) | |
print(len(t)) | |
print() |