Python Identify Operators

by Atakan

Now a variable in python has a value and has an id.
If we want to learn the id of a variable, let’s show it as an example

my_var = 100
my_var2 = 100

print(id(my_var))   #1562508121
print(id(my_var2))  #1562508121
print(id(100))      #1562508121
#What is being checked now is checking the ID values ​​ie 1562508121 == 1562508121
#Important warning: 
#If we are going to control its content, we shouldn't do a control like that of a variable..
#This may not always show the correct result

#We should use "is" for "id" control purposes.
if my_var is my_var2:
    print("yes same")


if my_var == 5:
    print("yes same")

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. OK Read More