首页 > 文章列表 > input在python中的使用注意

input在python中的使用注意

Python input
329 2022-08-07

1、函数input()接受一个参数,即要向用户显示的提示或说明,让用户知道该如何做。在这个示例中,用户将看到提示Tell me something, and I will repeat it back to you:。程序等待用户输入,并在用户按回车键后继续运行。

输入存储在变量message中,接下来的print(message)将输入呈现给用户:

Tell me something, and I will repeat it back to you: This is Fulade!
This is Fulade!

2、使用函数input()时,应指定清晰而易于明白的提示,准确地指出你希望用户提供什么样的信息——指出用户该输入任何信息的提示都行,如下所示:

name = input("Please enter your name: ")
print("Hello, " + name + "!")

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。