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 ===== | ||