x is y
x, y : input objects x is not y
x, y : input objects a=30
b=30
print(a is b ) # True
a=300
b=300
print(a is b ) # False
Why the second print() returns False ? a=-6
b=-6
print("Using is :",a is b)
print("using == :",a==b)
Output
Using is : False
using == : True
Example 2
a=30
b=30
print(a is b ) # True
a=300
b=300
print(a is b ) # False
print(a == b ) # True
x=500
print(type(x) is int) # True
Using float
x=100.34
print(type(x) is int) # False
x=100.34
print(type(x) is float) # True
x=30
y=400
print(type(x) is type(y)) # True
my_list1=[1,2,3]
my_list2=[4,5,6]
print(type(my_list1) is type(my_list2)) # True
Using frozenset()
my_list1=[1,2,3]
my_list2=frozenset([4,5,6])
print(type(my_list1) is type(my_list2)) # False
Using boolean
x=True
y=False
print(type(x) is type(y)) # True
x=56.78
y=100
print((x is not y)) # True
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.