Constantes natives¶
Un petit nombre de constantes existent dans le namespace natif. Elles sont :
- False¶
La valeur fausse du type
bool. Les assignations àFalsene sont pas autorisées et lèvent uneSyntaxError.
- True¶
La valeur vraie du type
bool. Les assignations àTruene sont pas autorisées et lèvent uneSyntaxError.
- 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.Note
When a binary (or in-place) method returns
NotImplementedthe 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 returningNotImplementedwill result in a misleading error message or theNotImplementedvalue being returned to Python code.Voir Implémentation des opérations arithmétiques pour des exemples.
Prudence
NotImplementedandNotImplementedErrorare not interchangeable. This constant should only be used as described above; seeNotImplementedErrorfor details on correct usage of the exception.Modifié dans la version 3.9: Evaluating
NotImplementedin a boolean context was deprecated.Modifié dans la version 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__¶
Cette constante est vraie si Python n'a pas été démarré avec une option
-O. Voir aussi l'expressionassert.
Note
Les noms None, False, True et __debug__ ne peuvent pas être réassignés (des assignations à ces noms, ou aux noms de leurs attributs, lèvent une SyntaxError), donc ils peuvent être considérés comme des "vraies" constantes.
Constantes ajoutées par le module site¶
Le module site (qui est importé automatiquement au démarrage, sauf si l'option de ligne de commande -S est donnée ajoute un certain nombre de constantes au namespace natif. Elles sont utiles pour l'interpréteur interactif et ne devraient pas être utilisées par des programmes.
- 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¶
Objets qui, lorsqu'ils sont affichés ou appelés, affichent le copyright ou les crédits, respectivement.
- license¶
Objet qui, lorsqu'il est affiché, affiche un message comme "Type license() to see the full license text", et lorsqu'il est appelé, affiche le texte complet de la licence dans un style paginé (un écran à la fois).