🎓 Welcome back to Digital Academy, the Complete Python Development Tutorial for Beginners, which will help you Learn Python from A to Z!
🖥️ Types of Operators in Python – Identity Operators in Python
Depending upon the type of operations you want to perform, there are 7 types of operators in Python: Arithmetic operators, Assignment operator, Comparison operators, Logical operators, Bitwise operators, Identity operators and Membership operators.
○ Identity Operators in Python – IS, IS NOT
Identity Operators, is and is not, are used to compare two values, or variables: not if they are equal, but if they are actually the same Object, located on the same part of the memory. Hence, the 2 variables that are equal does not necessarily imply that they are identical — with de same identity!
Operator | Meaning | Example
is | True operands are identical (same object) | x is True
is not | True if operands are not identical (not the same object) | x is not True
Here is an example of 2 objects that are equal, but not identical. x and y both refer to objects whose value is 5: they are equal. But they do not reference the same object, as you can verify: x and y do not have the same identity, and “x is y” returns False.
OUTPUT
x = 5 5
y = 4 + 1 5
OUTPUT
x == y True
x is y False
You saw previously that when you make an assignment like “x = y”, Python merely creates a second reference, to the same object – and you could confirm that fact with the id() function. You can also confirm it, using the “is” operator.
OUTPUT
id(x) 60307920
id(y) 60307920
In this specific case, since a and b reference the same object, it stands to reason that a and b would be equal, as well.
a = "I am a string"
b = a
OUTPUT
id(a) 55993992
id(b) 55993992
OUTPUT
a is b True
a == b True
Unsurprisingly, the opposite of “is”, is “is not”:
x = 5
y = 4 + 1
OUTPUT
x is not y True
Let’s play this video, stick around and watch until the end of this video! 👍🏻
– Digital Academy™ 🎓
***
☞ WATCH NEXT:
○ Data Types in Python – https://youtu.be/cweUByxBWiU
○ Operators in Python – https://youtu.be/-wDaVLkKOiU
○ IF Statements in Python – https://youtu.be/CC5seZ6OBJ4
○ FOR Loops in Python – https://youtu.be/JgH-D5DSTho
☞ WATCH MORE:
○ HOW TO Learn Python? Python Tutorial for Beginners [FULL Course] https://youtu.be/9hvnSZPMtuw
📖 Blog: http://digital.academy.free.fr/blog/
📖 Complete Python Development Course for Beginners [PLAYLIST]: http://digital.academy.free.fr/playlist/python-development-for-beginners
🛒 Shopping and Discounts: http://digital.academy.free.fr/store/
#Python #Tutorial #Beginners #Shorts
***
♡ Thanks for watching and supporting ♡
Please Subscribe. Hit the notification bell.
Like, Comment and Share.
***
♡ FOLLOW US ♡
✧ http://digital.academy.free.fr/
✧ https://twitter.com/DigitalAcademyy
✧ https://www.facebook.com/digitalacademyfr
✧ https://www.instagram.com/digital_academy_fr/
✧ https://www.youtube.com/c/DigitalAcademyOnline
♡ SUPPORT US ♡
✧ http://digital.academy.free.fr/join
✧ http://digital.academy.free.fr/donate
✧ http://digital.academy.free.fr/subscribe
✧ https://www.patreon.com/digital_academy
✧ https://www.buymeacoffee.com/digital_academy
***