python - 我们可以在 for 循环中声明一个空函数吗?
问题描述
def dec_list():
a = list()
for i in range(0, 3):
i = int(input("Enter the values: "))
a.append(i)
print(a)
x = dec_list()
print(x)
output:
[1,2,3]
total = 0
for num in x:
total = total + num
print(total)
output:
for num in x:
TypeError: 'NoneType' object is not iterable
关于代码的第一部分,我的输出正常(即 [1,2,3] ),但是当我尝试使用函数运行 for 循环时,会发生错误。你能帮我解决这个问题吗?
(对不起,如果问我问题的方式不恰当,这是我的第一次)
谢谢!
解决方案
类似的东西?
total = 0
for num in x:
pass
推荐阅读
- python - 使用带有指令的 Sphinx 包含多个 RST 文件 .. 包括::
- acumatica - 更改 PO 源的下拉值冗词(Drop-Ship、Purchase to Order)
- python - 使用子进程创建 konsole 实例不会释放进程
- docker - java.lang.IllegalStateException:无法在 localhost:49167 连接到 Ryuk
- replace - 翻译问题:TypeError:预期的字符串或类似字节的对象
- c - 如何将数据包作为入口注入接口?
- kql - 在 Azure 资源图资源管理器中创建联接
- sql - TSQL,如何从数据库中的多个 JSON 行中检索数据
- relational-database - 将一个实体与两个实体或两个实体之间的一种关系联系起来
- python - 如何将 numpy 数组中的 32 位 wav 文件转换为 24 位 wav 文件?