我试着建立一个基本的乘法表,但我一直得到这些“无”字。它们是什么意思?我怎样才能去掉它们?在
>>> def M(n):
... i = 1
... while i <= 6:
... print i*n, '\t',
... i = i +1
... print
>>> def printT():
... w = 1
... while w <= 6:
... print M(w)
... w = w + 1
...
>>> printT()
1 2 3 4 5 6
None
2 4 6 8 10 12
None
3 6 9 12 15 18
None
4 8 12 16 20 24
None
5 10 15 20 25 30
None
6 12 18 24 30 36
None
我也没有这种事。我键入了一个函数,并试图在另一个函数中使用它。但我写了“打印计算”。应该是“收益计算”。所以第二个函数给出'none'错误。检查我的代码:
在函数print()中,print M(w)没有返回任何内容。python中函数的隐式返回值为None,这是在循环期间打印的值。在
只需像这样重新编写函数:
将
print M(w)
替换为M(w)
。您正在打印M(w)
的返回值None
,因为您没有从该函数返回任何内容。在相关问题 更多 >
编程相关推荐