Python Glossary Русский

all Python 3Data typesterm

NoneType

none

The type of the single object None — the absence of a value. Used as a default value, as the return value of functions without a return, and as a sentinel.

Syntax

None

Compare with is / is not, never ==: None is the sole instance of its type, and == can be overridden by some class and surprise you. The name or "Guest" idiom is also a trap — it replaces any falsy value (0, "", [], False), not just None; for a None-only check use name if name is not None else "Guest".

Examples

x = None  # явное присваивание
print(x is None)  # → True (правильная проверка на None)
def f(): pass
print(f())  # → None (функция без return возвращает None)
def greet(name=None):
    name = name or "Гость"
    return f"Привет, {name}"
print(greet())  # → Привет, Гость

See also

Open in the full glossarydocs.python.orgReport an inaccuracy