CKTIS / Python
NoneType
El tipo del único objeto None se obtiene como types.NoneType y type(None).
Versión: Python 3.14; repository image, production runtime not attested
Sintaxis
from types import NoneTypeEl tipo del único objeto None se obtiene como types.NoneType y type(None).
Llamarlo sin argumentos devuelve el mismo objeto. La prueba is None distingue ausencia de valores falsos como cero o la cadena vacía.
Una unión anotada puede admitir None expresamente.
Ejemplos
from types import NoneType
def kind(x: int | str | None) -> str:
return "absent" if x is None else type(x).__name__
print(type(None) is NoneType, NoneType() is None)
print([kind(x) for x in (None, 0, "")])
print(isinstance(False, NoneType))
Resultado
True True ['absent', 'int', 'str'] False
Una unión anotada puede admitir None expresamente.