Back to Blog Home

What is Python raw_input ?

Jay Mishra| Python | 6 months, 1 week



 

raw_input() in python 2.x or input() in python 3.x, simply preset a prompt to the user. And as user enters the input data , it converts it into a string and returns it. 

 

Let’s take an example :

 

x = raw_input(“What is your Surname? ")

print "Hello, Mr %s." % x

 

And in case of python 3.x input() is used instead of raw_input :

 

x = input(“What is your Surname? ")

print "Hello, Mr %s." % x

 

 

According to the official python documentation :

raw_input()

If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that. When EOF is read, EOFError is raised.

 

If the readline module was loaded, then raw_input() will use it to provide elaborate line editing and history features.

 



Join 1000+ People Who Subscribe to Weekly Blog Updates

Back to Blog Home