En la segunda parte nos concentramos en las tuplas y los diccionarios. Tras la evaluación de todos estos programas podemos notar las similitudes y diferencias en el uso, declaración y manejo de estos elementos.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Prog8(tuple_dataypes)
#SE MUESTRAN LOS DISTINTOS TIPOS DE DATOS QUE PUEDE CONTENER UNA TUPLA
#empty tuple
#output:()
my_tuple=()
print(my_tuple)
#tuple having integers
#output:(1, 2, 3)
my_tuple=(1, 2, 3)
print(my_tuple)
#tuple with mixed datatypes
#output: (1, "Hello", 3.4)
my_tuple=(1, "Hello", 3.4)
print(my_tuple)
#nested tuple
#output:("mouse", (8, 4, 6), (1, 2, 3))
my_tuple=("mouse", (8, 4, 6), (1, 2, 3))
print(my_tuple)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Prog9(tuple_packing)
#DECLARAMOS VARIAS TUPLAS CON TIPOS DE DATOS DISTINTOS Y LOGRAMOS EMPACAR Y DESEMPACAR SUS COMPONENTES
my_tuple=()
print(my_tuple)
#tuple having integers
#output: (1,2,3)
my_tuple=(1,2,3)
print(my_tuple)
#nested tuple
my_tuple=("mouse", [8,4,6], (1,2,3))
lista=[1,2,3]
tup=(lista)
print(tup)
#tuple can be created without parentheses
#also called tuple packing
my_tuple=3,4.6,"dog"
print(my_tuple)
#tuple unpacking is also possible
a,b,c=my_tuple
print(a)
print(b)
print(c)
tupla1=(1,2,3)
tupla2=(4,5,6)
tupla3=(6,7,8)
tuplat=tupla1+tupla2+tupla3
print(tuplat)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Prog10(dictionary)
#diccionario
#ASIGNAMOS UN VALOR A CADA ELEMENTO DEL DICCIONARIO
edades={"Alberto":21,"Alan":20,"Hugo":19,"Fabian":20}
print(edades)
print(edades["Fabian"])
meses={"Enero":1,"Febrero":2,"Marzo":3,"Abril":4,"Mayo":5,"Junio":6,"Julio":7,"Agosto":8,"Septiembre":9,"Octubre":10,"Noviembre":11,"Diciembre":12,}
print(meses)
print(meses["Marzo"])
materias={}
#ASIGNAMOS VALORES DE LISTA A UN ELEMENTO DE DICCIONARIO
materias["lunes"]=[1025,1024]
materias["martes"]=[1210]
materias["miercoles"]=[1025,2530]
mat2={"lunes":[21,34],"martes":[12,10]}
#print(materias["lunes"])
print(mat2)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Comentarios
Publicar un comentario