Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Checking for None:
- result = some_function()
- if result is None:
- print("No result")
- else:
- print("Result available")
- # Comparing Singleton Objects:
- status = True
- if status is True:
- print("Status is True")
- # Caching Immutable Objects:
- a = "hello"
- b = "hello"
- if a is b:
- print("Same object")
- # Comparing Custom Objects:
- class MyClass:
- pass
- obj1 = MyClass()
- obj2 = obj1
- obj3 = MyClass()
- if obj1 is obj2:
- print("obj1 and obj2 refer to the same instance")
- if obj1 is not obj3:
- print("obj1 and obj3 are different instances")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement