freeCodeCamp/guide/portuguese/python/difference-between-is-and-e.../index.md

27 lines
785 B
Markdown
Raw Blame History

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

---
title: Difference between Python 'is' and '==' operators
localeTitle: Diferença entre os operadores Python 'is' e '=='
---
`is` é uma verificação da identidade do objeto - isto é, verificar se duas ou mais variáveis estão se referindo ao mesmo objeto. Você não pode sobrecarregar `is` .
`==` avalia como verdadeiro se o objeto referido pelas variáveis for igual. Você pode sobrecarregar `==` através do operador `__eq__` .
## Valor de retorno
O valor de retorno para ambos seria `True` ou `False` .
## Amostra de código
```
a = 2.3
a is 2.3 # => False
a == 2.3 # => True
a = [234,123,321]
b = [234,123,321]
a == b # => True
a is b # => False
a = b
a == b # => True
a is b # => True, because if we change a, b changes too
```