in Python by (32.2k points)
How to fix raw_input function in Python

What is the raw_input function? Is it a user interface? When do we use it?

1 Answer

0 votes
by (32.2k points)
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

This differs from input() in that the latter 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.

The "input" function converts the input you enter as if it were python code. "raw_input" doesn't convert the input and takes the input as it is given. Its advisable to use raw_input for everything. Usage:

>>a = raw_input()




raw_input is a form of input that takes the argument in the form of a string whereas the input function takes the value depending upon your input. Say, a=input(5) returns a as an integer with value 5 whereas  a=raw_input(5) returns a as a string of "5"

Related questions

0 votes
asked Jun 28, 2020 in Python by Robindeniel (20.8k points)