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 aFalse
são ilegais e levantamSyntaxError
.
- True¶
O valor verdadeiro do tipo
bool
. As atribuições aTrue
são ilegais e levantamSyntaxError
.
- 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 levantamSyntaxError
.None
é a única instância do tipoNoneType
.
- 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 thetypes.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 returnNotImplemented
, the interpreter will raise an appropriate exception. Incorrectly returningNotImplemented
will result in a misleading error message or theNotImplemented
value being returned to Python code.Consulte Implementando as operações aritméticas para ver exemplos.
Nota
NotImplementedError
andNotImplemented
are not interchangeable, even though they have similar names and purposes. SeeNotImplementedError
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 aDeprecationWarning
. It will raise aTypeError
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 tipotypes.EllipsisType
.
- __debug__¶
Esta constante é verdadeira se o Python não foi iniciado com uma opção
-O
. Veja também a instruçãoassert
.
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.
- copyright¶
- 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).