python - 这是我试图在 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'
解决方案
使用i % 5
代替list % 5
list1 = [12,15,18,21,26]
for i in list1:
if i % 5 == 0:
print(i)
break
推荐阅读
- javascript - 创建 Node-Red 自定义节点:配置不起作用,显示文本框而不是配置下拉列表
- c# - 为内存数据列表实现异步接口
- php - 正确使用 WP_Query 制作一些东西的问题
- c - C 和浮点数
- php - 如何使用 Laravel Eloquent ORM 搜索加密值?
- php - PHP:数组的数字之间的不完全差异
- javascript - 如何扩展组件
- laravel - 使用自己的 API Laravel 401 未经授权
- stripe-payments - 何时在 Stripe webhook 中注册“支付”事件
- python - Centering the string with format and a variable