-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpracticandoTyping.py
More file actions
66 lines (36 loc) · 1.41 KB
/
practicandoTyping.py
File metadata and controls
66 lines (36 loc) · 1.41 KB
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
# depende de la vesion de python
from typing import List, Optional, Union
def process_items(items:list[str]):
for item in items:
print(item)
def process_items(items:List[str]):
for item in items:
print(item)
# SI TENGO QUE TIPAR TUPLAS Y SETS
def process_items_tuplas(items_t:tuple[int,str],items_s:set[bytes]):
print(items_s, items_t)
return items_t, items_s
# SI tengo que tipar diccionarios , pongo el tipo para el key y para el value
def list_precios(precios:dict[str, float]):
for item , price in precios.items():
print(F"ITEM -> {item}- cuesta ${price}")
# si puede aceptar varios tipos de valores por ejemplo STR o INT , puedo usar un union o un |
def process_items_union(items:Union[int,str]):
print(items)
def process_items_union1(items:int | str):
print(items)
#Valores Opcionales Optional o usando None PARA HACERLO OPCIONAL TENES QUE USAR EL NONE SI O SI
def process_items_optional(item:str|None=None):
if(item):
return "Hay un item"
else:
return "No hay"
def process_items_optional1(item:Optional[str]=None):
if(item):
return "Hay un item"
else:
return "No hay"
process_items_tuplas((1,'tupla'),{b"hola",b"mundo"})
# process_items(['test1','test2','535'])
# list_precios({'blusa':22.3,'jean':120.2})
print(process_items_optional1('holla'))