Вбудовані константи¶
Невелика кількість констант живе у вбудованому просторі імен. Вони є:
- False¶
Помилкове значення типу
bool
. ПрисвоєнняFalse
є незаконним і викликаєSyntaxError
.
- True¶
Справжнє значення типу
bool
. ПрисвоєнняTrue
є незаконним і викликаєSyntaxError
.
- None¶
An object frequently used to represent the absence of a value, as when default arguments are not passed to a function. Assignments to
None
are illegal and raise aSyntaxError
.None
is the sole instance of theNoneType
type.
- NotImplemented¶
A special value which should be returned by the binary special methods (e.g.
__eq__()
,__lt__()
,__add__()
,__rsub__()
, etc.) to indicate that the operation is not implemented with respect to the other type; may be returned by the in-place binary special methods (e.g.__imul__()
,__iand__()
, etc.) for the same purpose. It should not be evaluated in a boolean context.NotImplemented
is the sole instance of thetypes.NotImplementedType
type.Примітка
When a binary (or in-place) method returns
NotImplemented
the interpreter will try the reflected operation on the other type (or some other fallback, depending on the operator). If all attempts returnNotImplemented
, the interpreter will raise an appropriate exception. Incorrectly returningNotImplemented
will result in a misleading error message or theNotImplemented
value being returned to Python code.Перегляньте приклади Реалізація арифметичних дій.
Застереження
NotImplemented
andNotImplementedError
are not interchangeable. This constant should only be used as described above; seeNotImplementedError
for details on correct usage of the exception.Змінено в версії 3.9: Evaluating
NotImplemented
in a boolean context is deprecated. While it currently evaluates as true, it will emit aDeprecationWarning
. It will raise aTypeError
in a future version of Python.
- Ellipsis¶
Те саме, що літерал з крапками «
...
». Спеціальне значення, яке використовується переважно разом із розширеним синтаксисом нарізки для визначених користувачем типів даних контейнера.Ellipsis
є єдиним екземпляром типуtypes.EllipsisType
.
- __debug__¶
Ця константа є істинною, якщо Python не було запущено з параметром
-O
. Дивіться також операторassert
.
Примітка
Імена None
, False
, True
і __debug__
не можна перепризначити (присвоєння їм, навіть як імені атрибута, викликає SyntaxError
), тому їх можна вважати «справжніми» константами.
Константи, додані модулем site
¶
Модуль site
(який імпортується автоматично під час запуску, за винятком випадків, коли задано параметр командного рядка -S
) додає кілька констант до вбудованого простору імен. Вони корисні для інтерактивної оболонки інтерпретатора і не повинні використовуватися в програмах.
- quit(code=None)¶
- exit(code=None)¶
Об’єкти, які під час друку друкують повідомлення на зразок «Використовуйте quit() або Ctrl-D (тобто EOF) для виходу», а під час виклику викликають
SystemExit
із зазначеним кодом виходу.
- help
Object that when printed, prints the message «Type help() for interactive help, or help(object) for help about object.», and when called, acts as described
elsewhere
.
- copyright¶
- credits¶
Об’єкти, які під час друку або виклику друкують текст авторських прав або кредитів відповідно.
- license¶
Об’єкт, який під час друку друкує повідомлення «Введіть licence(), щоб побачити повний текст ліцензії», а під час виклику відображає повний текст ліцензії у вигляді пейджера (по одному екрану).