举例说明:
def contain(): score = 4 if score in num: return True,score; num = [1,2,3,0] iscontain,score = contain() print iscontain,score结果:
>>> Traceback (most recent call last): File "D:\Program Files\python\chengxu\temp.py", line 8, in <module> iscontain,score = contain() TypeError: 'NoneType' object is not iterable</span> >>>
解决方法:加上else语句
def contain(): score = 4 if score in num: return True,score; else: return False,score; num = [1,2,3,0] iscontain,score = contain() print iscontain,score结果:
>>> False 4
参考文章:
http://blog.csdn.net/dataspark/article/details/9953225