print statement inside of input returns with a “none”

后端 未结 1 1122
耶瑟儿~
耶瑟儿~ 2020-11-28 16:39

I am working on a little program and I want to use:

ans = int(input(print(multi,\'x\',num,\'=\')))

This works well except for the fact that

相关标签:
1条回答
  • 2020-11-28 17:04

    input takes a prompt string as its argument, which it will print automatically, but print returns None; it is this that gets printed by input. Your code is equivalent to:

    prompt = print(...) # prompt == None
    ans = int(input(prompt)) 
    

    Instead, use str.format to build the prompt and pass it straight to input:

    ans = int(input('{0}x{1}='.format(multi, num)))
    
    0 讨论(0)
提交回复
热议问题