input () and raw_input ()

2

According to the Python 2.x documentation, it is recommended to use the raw_input function instead of input . Conversely, in the Python 3.x documentation, the raw_input function does not even appear. So does the input function in Python 3.x replace the raw_input ? Function?

    
asked by anonymous 08.08.2016 / 01:07

2 answers

2

In Python 2 there are the functions input and raw_input , but the first is rarely used because it only accepts syntactically valid literals, that is, numbers, or quoted strings, etc. The raw_input function is much more useful: it accepts any string , and it is your responsibility to deal with it.

In Python 3 the raw_input function was renamed input , and the old input function practically useless was removed.

In Python 3 several "cleanups" of this type happened.

    
08.08.2016 / 01:19
3

Yes, input of Python 3.x is raw_input of Python 2.x. This change can be found in the version 3.0 changelog :

  

PEP 3111: raw_input() renamed to input() . That is, the new input() function reads a line from sys.stdin and returns it with the trailing newline stripped. It raises EOFError if the input is terminated prematurely. To get the old behavior of input() , use eval(input()) .

For more details, see PEP 3111 .

    
08.08.2016 / 01:17