Python报错:not all arguments converted during string formatting
>>> d= ['ewf','2']
>>> if d[1]%2 ==0:
print('defe')
Traceback (most recent call last):
File "<pyshell#20>", line 1, in <module>
if d[1]%2 ==0:
TypeError: not all arguments converted during string formatting
报错原因:定义列表的d [1]元素时,赋值的是'2',是一个字符串,所以在执行d [1]%2时,前后格式不匹配所以报错
>>> c=['dgfre',3]
>>> if c[1]%2 == 1:
print('dfgd')
dfgd