且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检查对象是列表还是元组(但不是字符串)?

更新时间:2023-11-29 09:25:16

仅在 python 2(不是 python 3)中:

In python 2 only (not python 3):

assert not isinstance(lst, basestring)

实际上就是你想要的,否则你会错过很多类似于列表但不是listtuple的子类的东西.

Is actually what you want, otherwise you'll miss out on a lot of things which act like lists, but aren't subclasses of list or tuple.