Janezcka Janezcka - 1 year ago 78
Python Question

raw_input function in Python

What is the

function? Is it a user interface? When do we use it?

Answer Source

It presents a prompt to the user (the optional arg of raw_input([arg])), gets input from the user and returns the data input by the user in a string. See the docs for raw_input().


name = raw_input("What is your name? ")
print "Hello, %s." % name

The difference with input() is that it tries to interpret the input given by the user; it is usually best to avoid input() and to stick with raw_input() and custom parsing/conversion code.