Test if a variable is a list or tuple

前端 未结 13 1387
余生分开走
余生分开走 2020-12-22 16:53

In python, what\'s the best way to test if a variable contains a list or a tuple? (ie. a collection)

Is isinstance() as evil as suggested here? http://w

13条回答
  •  春和景丽
    2020-12-22 17:25

    Another easy way to find out if a variable is either list or tuple or generally check variable type would be :

        def islist(obj):
    
            if ("list" in str(type(obj)) ): return True
    
            else : return False
    

提交回复
热议问题