Herramientas de usuario

Herramientas del sitio


wiki2:python3

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

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>​
wiki2/python3.1593433538.txt.gz · Última modificación: 2020/06/29 13:25 (editor externo)