Sitemap
AlmaBetter

Your home for data science. Concepts, ideas, codes and blogs from students of AlmaBetter. We are building the next-gen AI ecosystem https://www.almabetter.com

Python input() and raw_input() function.

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.

Get Shubham Dubey’s stories in your inbox

Join Medium for free to get updates from this writer.

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.

Press enter or click to view image in full size
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

Written by Shubham Dubey

I write to better understand what I had learned.

AlmaBetter

Published in AlmaBetter

Your home for data science. Concepts, ideas, codes and blogs from students of AlmaBetter. We are building the next-gen AI ecosystem https://www.almabetter.com