Constantes natives

Un petit nombre de constantes existent dans le namespace natif. Elles sont :

False

La valeur fausse du type bool. Les assignations à False ne sont pas autorisées et lèvent une SyntaxError.

True

La valeur vraie du type bool. Les assignations à True ne sont pas autorisées et lèvent une 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.

Note

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.

Voir Implémentation des opérations arithmétiques pour des exemples.

Note

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

Modifié dans la version 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

Identique au littéral points de suspension ("..."). Valeur spéciale utilisée principalement de manière conjointe avec la syntaxe de découpage (slicing) étendu pour les conteneurs personnalisés. Ellipsis est la seule instance de types.EllipsisType.

__debug__

Cette constante est vraie si Python n'a pas été démarré avec une option -O. Voir aussi l'expression assert.

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)

Objets qui, lorsqu'ils sont représentés, affichent un message comme "Use quit() or Ctrl-D (i.e. EOF) to exit", et lorsqu'ils sont appelés, lèvent un SystemExit avec le code de retour spécifié.

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).