如何检查变量是否包含 Pygame 中的矩形?

How to check if a variable contains a rect in Pygame?

所以如果我像这样向变量添加一个矩形

box = pygame.Rect(x, y, w, h)

如何检查变量 rect 是否包含 pygame.Rect?理想情况下,它会 return 类似于此

int = 9

#int is not a rect
#box is a rect

使用isinstance(object, classinfo):

Return True if the object argument is an instance of the classinfo argument [...]

if isinstance(box, pygame.Rect):
    print('is a rect')
else:
    print('is not a rect')