The Python raw_input()
function is used to read a string from standard input such as keyboard. This way a programmer is able to include user inserted data into a program. Let’s start with a simple example using python script to ask for an user name.
print "What is your name?" name = raw_input() print "Hello %s!" % name
First, we print string What is your name?
telling the user what we expect him to input. Next, using the raw_input()
function the standard input is assigned to a variable name
. Lastly, we print the value of variable name
to standard output.
$ python input.py What is your name? Monty Python Hello Monty Python!