python - How to check if a variable contains a rect in Pygame?
问题描述
So if I add a rect to a variable like so
box = pygame.Rect(x, y, w, h)
How do I check if the variable rect holds a pygame.Rect
? Ideally it would return something similar to this
int = 9
#int is not a rect
#box is a rect
解决方案
Use 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')
推荐阅读
- angular - 将管道的功能声明为静态方法并从模板中使用它是好还是坏的做法?
- node.js - 构造异步 Express GET 请求的最佳方式
- c# - 链接多个 IF - 仅当 current 为 false 时才评估 next
- sql - Rails ActiveRecord - 按匹配号查询订单
- bash - 读取浮点数
- printing - 打印 OPL 中的每个进程
- javascript - Win check 的 Java 脚本刽子手问题
- r - R中基本数据类型的最小/最大值是多少?
- python-3.x - Deep Q learning-Training问题
- swift - 使用 Animoji/Memoji 作为头像