Python input() and raw_input() function.

Shubham Dubey
AlmaBetter
Published in
2 min readFeb 10, 2022
input() and raw_input() difference in python

For python2

we have raw_input() function it will take different values from the user and return the output in the form of a string irrespective of the input values.

Difference between the input() and raw_input() function in python. The raw_input() function in python.

For example, this problem in python2 gives string.

Whereas the input() function in python2 will return the same value type as the user entered.

Difference between the input() and raw_input() function in python. The input() function in python.

For Python3

The raw_input() function is not available for python3. The input() function in python3 is similar to the raw_input() function in python2. It means whatever type of data you input in python3 it will give you string as an output.

The input() function in python. Difference between the input() and raw_input() function in python.

For example:

Example of input() function in python

Here, we can see that if we input integer values in python3 using the input function it will give a string as an output. To get an integer as an output we have to use the int() function with the input() function.

Similarly, we have to use different functions with input function for getting different outputs types like float, list, etc.

--

--

Shubham Dubey
AlmaBetter

I write to better understand what I had learned.