我知道两者的作用,但最佳实践是什么?
如果我有与输入相关的文本列表,我应该将所有内容放入 input() 函数中,还是应该像下面那样执行单独的打印函数?
print(
f"Have you put the {name} image ./images/{name}/ or do you want to "
"specify a custom directory?"
"\nRespond with '1' or '2'.\n"
f"Option 1: ./images/{name}\n"
"Option 2: custom directory"
)
use_custom = input("> ")
如你所见,这不是一个“我如何使用python”的问题,而更像是一个“python应该如何写”的问题。
但是底线是,无论您最终使用什么,结果都是一样的。如果文本等需要更改,则可能更容易阅读/重构。输入始终保持不变。
亲切的问候!