Equality Vs Identity Operator in Python | Difference between '==' and 'is' #python #coding #shorts

preview_player
Показать описание
while comparing two strings, you can either use the equality operator or you may use the identity operator.
In both cases, you might get the same result. but they are not the same.

Now the question is when to use whom?
Use the identity operator, to check whether two variables point to the same object in memory.
whereas using the equality operator to compare if the values for the two variables are the same. Irrespective of where they’re stored in memory.

#leetcode #dataanalysis #dataanalytics #matplotlib #datascience #google #machinelearning #ai
--------------------------------------------------------------------------------------------------------------------------------------------------
Show your support by subscribing to my channel.

Thank you
Рекомендации по теме
Комментарии
Автор

Hi Saif, thanks for sharing the video. It would be great if you could make a video on Python library 'eel'. Thanks a lot!

abdullahjaffrey
Автор

shouldn't 'var1 is var2' return False in the first example since the two strings are located in different parts of memory?

edit: I've just checked and they aren't. when you assign two variables the same string like in the video, python can optimise memory and have them point to the same object.

interesting how this applies to small strings only tho

nodovu
join shbcf.ru