Wbudowane stałe¶
We wbudowanej przestrzeni nazw znajduje się kilka stałych. Są to:
- False¶
Wartość „fałsz” typu
bool. Przypisania doFalsesą niedozwolone i rzucają wyjątkiemSyntaxError.
- True¶
Wartość „prawda” typu
bool. Przypisania doTruesą niedozwolone i rzucają wyjątkiemSyntaxError.
- None¶
An object frequently used to represent the absence of a value, as when default arguments are not passed to a function. Assignments to
Noneare illegal and raise aSyntaxError.Noneis the sole instance of theNoneTypetype.
- 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.NotImplementedis the sole instance of thetypes.NotImplementedTypetype.Informacja
Gdy metoda binarna (albo operująca w miejscu) zwróci
NotImplemented, interpreter spróbuje wykonać odpowiadającą jej operację na drugim typie (albo innego mechanizmu rezerwowego, w zależności od rodzaju operatora). Dopiero gdy wszystkie próby zwrócąNotImplemented, interpreter rzuci odpowiednim wyjątkiem. Nieprawidłowe zwracanieNotImplementedspowoduje wyświetlenie mylnego komunikatu błędu lub też zwrócenie wartościNotImplementeddo kodu Pythona.Zobacz przykłady w Implementing the arithmetic operations.
Ostrzeżenie
NotImplementedandNotImplementedErrorare not interchangeable. This constant should only be used as described above; seeNotImplementedErrorfor details on correct usage of the exception.Zmienione w wersji 3.9: Evaluating
NotImplementedin a boolean context was deprecated.Zmienione w wersji 3.14: Evaluating
NotImplementedin a boolean context now raises aTypeError. It previously evaluated toTrueand emitted aDeprecationWarningsince Python 3.9.
- Ellipsis¶
The same as the ellipsis literal „
...”, an object frequently used to indicate that something is omitted. Assignment toEllipsisis possible, but assignment to...raises aSyntaxError.Ellipsisis the sole instance of thetypes.EllipsisTypetype.
- __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)¶
Objects that when printed, print a message like „Use quit() or Ctrl-D (i.e. EOF) to exit”, and when accessed directly in the interactive interpreter or called as functions, raise
SystemExitwith the specified exit code.
- help
Object that when printed, prints the message „Type help() for interactive help, or help(object) for help about object.”, and when accessed directly in the interactive interpreter, invokes the built-in help system (see
help()).
- copyright¶
- 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).