Python 用户输入
创建于 2024-12-03 /
21
字体:
[默认]
[大]
[更大]
用户输入
Python 允许命令行输入。
这意味着我们能够要求用户输入。
Python 3.6 中的方法与 Python 2.7 略有不同。
Python 3.6 使用 input() 方法。
Python 2.7 使用 raw_input() 方法。
下面的例子会询问用户的姓名,当您输入名字时,名字将打印到屏幕上:
Python 3.6
username = input("Enter username:")print("Username is: " + username)
运行实例 »
Python 2.7
username = raw_input("Enter username:")print("Username is: " + username)
运行实例 »
当执行到 input()
函数时,Python 停止执行,并在用户给出一些输入后继续执行。
0 人点赞过