Constantes embutidas

Um pequeno número de constantes são definidas no espaço de nomes embutido da linguagem. São elas:

False

O valor falso do tipo bool. As atribuições a False são ilegais e levantam SyntaxError.

True

O valor verdadeiro do tipo bool. As atribuições a True são ilegais e levantam SyntaxError.

None

Um objeto frequentemente usado para representar a ausência de um valor, como quando os argumentos padrão não são passados para uma função. As atribuições a None são ilegais e levantam SyntaxError. None é a única instância do tipo NoneType.

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.

Nota

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.

Consulte Implementando as operações aritméticas para ver exemplos.

Nota

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

Alterado na versão 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

O mesmo que as reticências literais “...”. Valor especial usado principalmente em conjunto com a sintaxe de divisão estendida para tipos de dados de contêiner definidos pelo usuário. Ellipsis é a única instância do tipo types.EllipsisType.

__debug__

Esta constante é verdadeira se o Python não foi iniciado com uma opção -O. Veja também a instrução assert.

Nota

Os nomes None, False, True e __debug__ não podem ser reatribuídos (atribuições a eles, mesmo como um nome de atributo, levantam SyntaxError ), para que possam ser consideradas “verdadeiras” constantes.

Constantes adicionadas pelo módulo site

O módulo site (que é importado automaticamente durante a inicialização, exceto se a opção de linha de comando -S for fornecida) adiciona várias constantes ao espaço de nomes embutido. Eles são úteis para o console do interpretador interativo e não devem ser usados em programas.

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

Objetos que, quando impressos, imprimem uma mensagem como “Use quit() or Ctrl-D (i.e. EOF) to exit” e, quando chamados, levantam SystemExit com o código de saída especificado.

credits

Objetos que ao serem impressos ou chamados, imprimem o texto dos direitos autorais ou créditos, respectivamente.

license

Objeto que, quando impresso, imprime a mensagem “Type license() to see the full license text” e, quando chamado, exibe o texto completo da licença de maneira semelhante a um paginador (uma tela por vez).