输入内部的打印语句返回“无”

0 python input python-3.x

我正在编写一个小程序,我想使用:

ans = int(input(print(multi,'x',num,'=')))
Run Code Online (Sandbox Code Playgroud)

这很好,除了在打印打印语句后没有提示的事实。喜欢:

49 x 7 =
None
Run Code Online (Sandbox Code Playgroud)

如果可能的话,如何删除“无”?我也确实搜索了这个问题,但是什么也没有在输入中返回空值。

jon*_*rpe 6

inputprompt字符串作为参数,它将自动打印,但print返回None;这是由打印的input。您的代码等效于:

prompt = print(...) # prompt == None
ans = int(input(prompt)) 
Run Code Online (Sandbox Code Playgroud)

而是使用str.format构建提示并将其直接传递给input

ans = int(input('{0}x{1}='.format(multi, num)))
Run Code Online (Sandbox Code Playgroud)