diff options
| author | 2021-04-12 10:09:43 -0400 | |
|---|---|---|
| committer | 2021-04-12 10:09:43 -0400 | |
| commit | 7a07fa89746e70f1539ae57912ed19e5690a561a (patch) | |
| tree | 9732df8fee8e5fb607c51cb31acf5b8ad99806a7 | |
| parent | Merge pull request #1516 from ToxicKidz/sorted-available-channels (diff) | |
Create identity.md
Tag to demonstrate the difference between `is` and `==`.
| -rw-r--r-- | bot/resources/tags/identity.md | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/bot/resources/tags/identity.md b/bot/resources/tags/identity.md new file mode 100644 index 000000000..32995aef6 --- /dev/null +++ b/bot/resources/tags/identity.md @@ -0,0 +1,25 @@ +**Identity vs. Equality** + +Should I be using `is` or `==`? + +To check if two things are equal, use the equality operator (`==`). +```py +x = 5 +if x == 5: + print("x equals 5") +if x == 3: + print("x equals 3") +# Prints 'x equals 5' +``` + +To check if two things are actually the same thing in memory, use the identity comparison operator (`is`). +```py +x = [1, 2, 3] +y = [1, 2, 3] +if x is [1, 2, 3]: + print("x is y") +z = x +if x is z: + print("x is z") +# Prints 'x is z' +``` |