Wbudowane stałe

We wbudowanej przestrzeni nazw znajduje się kilka stałych. Są to:

False

Wartość „fałsz” typu bool. Przypisania do False są niedozwolone i rzucają wyjątkiem SyntaxError.

True

Wartość „prawda” typu bool. Przypisania do True są niedozwolone i rzucają wyjątkiem 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 a SyntaxError. None is the sole instance of the NoneType 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 the types.NotImplementedType type.

Informacja

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 return NotImplemented, the interpreter will raise an appropriate exception. Incorrectly returning NotImplemented will result in a misleading error message or the NotImplemented value being returned to Python code.

Zobacz przykłady w Implementing the arithmetic operations.

Informacja

NotImplementedError and NotImplemented are not interchangeable, even though they have similar names and purposes. See NotImplementedError for details on when to use it.

Zmienione w wersji 3.9: Evaluating NotImplemented in a boolean context is deprecated. While it currently evaluates as true, it will emit a DeprecationWarning. It will raise a TypeError in a future version of Python.

Ellipsis

To samo co literalny zapis wielokropka „...”. Wartość specjalna używana głównie w połączeniu z rozszerzoną składnią krojenia typów danych kontenerów zdefiniowanych przez użytkownika. Ellipsis jest jedyną instancją typu types.EllipsisType.

__debug__

Ta stała ma wartość True jeśli Python nie został uruchomiony z opcją -O. Zobacz także deklarację assert.

Informacja

Nazwy None, False, True oraz __debug__ nie mogą być przypisane ponownie (przypisania do nich, nawet jako nazwa atrybutu, rzucają SyntaxError), więc mogą być uważane za „prawdziwe” stałe.

Stałe dodane przez moduł site

Moduł site (który jest importowany automatycznie podczas uruchamiania, z wyjątkiem sytuacji, gdy podano opcję wiersza poleceń -S) dodaje kilka stałych do wbudowanej przestrzeni nazw. Są one przydatne w interaktywnej powłoce interpretera i nie powinny być używane w programach.

quit(code=None)
exit(code=None)

Obiekty, które, gdy ich nazwa zostanie wpisana w powłoce - wyświetlają wiadomość w formie „Use quit() or Ctrl-D (i.e. EOF) to exit”, a gdy wywołane - rzucą wyjątek SystemExit z podanym kodem wyjścia.

credits

Obiekty, które, gdy wypisane lub wywołane - wyświetlają treść odpowiednio praw autorskich i słów uznania.

license

Obiekt, który, gdy jego nazwa zostanie wpisana w powłoce - wyświetla wiadomość „Type license() to see the full license text”, a gdy wywołany - wyświetla pełny tekst licencji w sposób podobny do pagera (jeden ekran na raz).