is operator in Python

 For professionals and Beginners 

is operator is just like == , is used to compare memory addresses .

x=10
y=10

x is y
output= True
y is x
output= True

int datatype is immutable hence  both x and y variable pointing to same object hence we get True

to check address use id() function , ex : id(x) is id( y)

Note IMP : we getting same memory address if number in range of 0 to 256 , if number out side the range then separate object craeted.


Interesting fact : 

x=10.0
y=10.0

x is y
output : False

Note : for float value each time separate object created, same for complex.

x=10+20j
y=10+20j

x is y
output: False


Note reusing same object concept applicable on
int - range 0 to 256
str-always
bool-slways




 


 

Comments

Popular posts from this blog

Filter In Javafx

Kotlin with StandAlone Complier