Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anterior Revisión previa Próxima revisión | Revisión previa | ||
|
wiki2:python3 [2020/06/29 12:25] alfred [Python type checking] |
wiki2:python3 [2022/10/12 19:03] (actual) |
||
|---|---|---|---|
| Línea 426: | Línea 426: | ||
| asyncio.run(main()) | asyncio.run(main()) | ||
| </code> | </code> | ||
| + | |||
| + | ===== Enums ===== | ||
| + | |||
| + | <code python> | ||
| + | from enum import Enum | ||
| + | |||
| + | class Numbers(Enum): | ||
| + | ONE = 1 | ||
| + | TWO = 2 | ||
| + | |||
| + | number = Numbers(2) # <Numbers.TWO: 2> | ||
| + | number1 = Numbers["ONE"] # <Numbers.TWO: 2> | ||
| + | members = [n for n in Numbers] # [<Numbers.ONE: 1>, <Numbers.TWO: 2>] | ||
| + | values = [n.value for n in Numbers] # [1, 2] | ||
| + | </code> | ||
| + | |||
| + | ==== Links ==== | ||
| + | |||
| + | * https://realpython.com/python-enum/ | ||
| + | |||
| ===== Python type checking ===== | ===== Python type checking ===== | ||
| Línea 478: | Línea 498: | ||
| def headline( | def headline( | ||
| - | |||
| text, # type: str | text, # type: str | ||
| - | |||
| width=80, # type: int | width=80, # type: int | ||
| - | |||
| fill_char="-", # type: str | fill_char="-", # type: str | ||
| - | |||
| ): # type: (...) -> str | ): # type: (...) -> str | ||
| - | |||
| return f" {text.title()} ".center(width, fill_char) | return f" {text.title()} ".center(width, fill_char) | ||
| </code> | </code> | ||