1.判断一个值是否是List数组,如果不是,将其转化为List
x = '123' print('原类型:%s' % type(x)) def isiterable(obj): try: iter(obj) return True except TypeError: # not iterable return False if not isinstance(x, list) and isiterable(x): x = list(x) print(x) print(x[1]) print('转化后的类型:%s' % type(x))