+ 2

Whats the difference between raw_input() and input() in Python 2 & 3?

21st Feb 2018, 4:17 PM
Juan Antonio
Juan Antonio - avatar
4 Answers
+ 3
input() :interprets and evaluates the input which means that if user enters integer,an integer will be returned ,if user enters string,string is returned. raw_input():raw_input() takes exactly what user typed and passes it back as string .It doesn’t interprets the user input.Even an integer value of 10 is entered or a list is entered its type will be of string only.
21st Feb 2018, 4:33 PM
Dimanjan Dahal
Dimanjan Dahal - avatar
+ 7
Actually, input() always returns a string in Python 3, much like raw_input() does for Python 2.
21st Feb 2018, 4:46 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 1
In Python 2, `input()` is equivalent to `eval(raw_input())`. In Python 3, `raw_input` was renamed to `input`, replacing the previous Python 2 function. Pretty much what @Dimanjan already said.
22nd Feb 2018, 1:07 AM
Edgar Garrido
Edgar Garrido - avatar