Advertisement
here2share

# either_instance.py

Feb 10th, 2024
1,075
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. # either_instance.py
  2.  
  3. class Square:
  4.     pass
  5.  
  6. class Circle:
  7.     pass
  8.  
  9. class Triangle:
  10.     pass
  11.  
  12. def detect_shape(shape):
  13.     if isinstance(shape, (Square, Circle)):
  14.         print("It's either a Square or a Circle.")
  15.         # Your further logic goes here
  16.     else:
  17.         print("It's NOT a Square or a Circle.")
  18.  
  19. # Example usage
  20. square_instance = Square()
  21. circle_instance = Circle()
  22. triangle_instance = Triangle()
  23.  
  24. detect_shape(square_instance) # Output: It's either a Square or a Circle.
  25. detect_shape(triangle_instance) # Output: It's NOT a Square or a Circle.
  26. detect_shape(circle_instance) # Output: It's either a Square or a Circle.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement