'input()'函数是Python的内置函数,用于从用户那里获取输入。它会显示一个提示信息,等待用户输入,然后返回用户输入的字符串。
input()函数的基本语法为:
input([prompt])
其中prompt是可选字符串,用于显示在输入提示符前,提示用户进行输入。
比如希望用户输入一个整数:
>>> integer = input('Please enter an integer:')
Please enter an integer:
因此input函数可以用于获取数值输入,由于input()函数返回的是字符串,因此需要用int()或float()函数进行转换:
age = int(input("Enter your age: "))
print("You are " + str(age) + " years old.")
综上,input()函数是Python中用于获取用户输入的工具,可以应用于多种交互式应用场景。