如果args
是整数,我需要做一件事,如果args
是字符串,则需要做一件事。如何检查变量的类型? Python
我该如何检查类型?例如:
def handle(self, *args, **options):
if not args:
do_something()
elif args is integer:
do_some_ather_thing:
elif args is string:
do_totally_different_thing()
你的权利。是一览。 – Pol 2010-08-09 14:30:41
是否有任何使用'isinstance(s,types.IntType)'而不是'isinstance(s,int)'的偏好呢?还是仅仅为了与你提到的两种类型的字符串一致?只是好奇。 – 2010-08-09 14:35:31
您的解决方案与python 3.1不兼容! – banx 2010-08-09 14:37:11