如何在Python中从用户输入一个字符串?

如何在Python中从用户输入一个字符串?

在Python中,有几种方法可以从用户输入一个字符串。最常见的方法是使用内置函数input()。该函数允许用户输入一个字符串,然后将其存储为一个变量以供程序使用。

示例

下面是一个在Python中从用户输入字符串的示例−

# Define a variable to store the input name = input("Please enter your name: ") 1. Print the input print("Hello, " + name + "! Good to see you.") 登录后复制