Test if a variable is a list or tuple

前端 未结 13 1381
余生分开走
余生分开走 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:19

    On Python 2.8 type(list) is list returns false
    I would suggest comparing the type in this horrible way:

    if type(a) == type([]) :
      print "variable a is a list"
    

    (well at least on my system, using anaconda on Mac OS X Yosemite)

提交回复
热议问题