首页 > 解决方案 > 这是我试图在 Jupyter 上运行的一个简单代码,它来了

问题描述

list=[12,15,18,21,26]
for i in list:
    if list % 5 == 0:
        print(list)
        break


Traceback (most recent call last)
<ipython-input-31-dbdee19fa7cd> in <module>
      1 list=[12,15,18,21,26]
      2 for i in list:
----> 3     if list % 5 == 0:
      4         print(list)
      5         break

TypeError: unsupported operand type(s) for %: 'list' and 'int'

标签: pythonjupyter-notebook

解决方案


使用i % 5代替list % 5

list1 = [12,15,18,21,26] 
for i in list1: 
    if i % 5 == 0: 
        print(i) 
        break


推荐阅读