1.语法说明
input()函数可以提示并接收用户的输入内容,将所有的输入年内容按照字符串进行处理,返回一个字符串。input()函数的基本用法如下:
input(prompt)
参数说明:prompt(可选参数,表示提示信息)。
示例1:接收用户输入的内容并保存到变量中,代码如下:
name=input("Please enter the name of your favorite football star: ")
#提示输入你最喜欢的足球明星的名字
print(name)
#输出名字
输入Cristiano Ronaldo,输出结果为:
>>>name=input("Please input the name of your favorite football star:")
Please input the name of your favorite football star:Cristiano Ronaldo
>>> print(name)
Cristiano Ronaldo
示例2:使用input()函数提示输入内容,将C罗效力过的俱乐部名称保存到列表中并输出,代码如下:
#输入C罗效力过的