DEV Community

Avnish Jayaswal
Avnish Jayaswal

Posted on

Python raw_input

Python raw_input() function is removed from Python 3.x versions. But it exists in Python 2.x. Actually, it has the same functionality same as the python input() function of Python 3.x.

The raw_input() function reads a line from input (i.e. the user) and returns a string by stripping a trailing newline.

raw_input syntax Python v2.x

mydata = raw_input('Prompt :')
print (mydata)
Enter fullscreen mode Exit fullscreen mode

raw_input syntax Python v3.x

mydata = input('Prompt :')
print (mydata)
Enter fullscreen mode Exit fullscreen mode

Python raw_input() examples

In this example, read the user name using raw_input() and display it back on the screen using print():

#!/usr/bin/python
name=raw_input('Enter your name : ')
print ("Hi %s, Let us be friends!" % name);
Enter fullscreen mode Exit fullscreen mode

Read More : Python raw_input

Top comments (0)