Skip to content

Identity is not the same thing as equality in Python #5713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2019

Conversation

cclauss
Copy link
Contributor

@cclauss cclauss commented May 22, 2019

Identity is not the same thing as equality in Python. In this instance, we want the latter.

Use ==/!= to compare str, bytes, and int literals.

$ python

>>> result = 'choic'
>>> result += 'e'
>>> result == 'choice'
True
>>> result is 'choice'
False

Identity is not the same thing as equality in Python.  In this instance, we want the latter.

Use ==/!= to compare str, bytes, and int literals.

$ __python__
```python
>>> result = 'choic'
>>> result += 'e'
>>> result == 'choice'
True
>>> result is 'choice'
False
```
Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

Thanks.

@humitos humitos merged commit 8726fb6 into readthedocs:master May 22, 2019
@cclauss cclauss deleted the patch-1 branch May 22, 2019 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants