Input or raw_input?

Asked

Viewed 17,548 times

8

Can anyone tell me the difference between input and raw_input in Python and how to use both?

2 answers

5

The difference is that raw_input() does not exist in the Python 3.x, while input() exists. In fact the old raw_input() was renamed to input() and the old input() no longer exists (although it can be simulated using eval(input()).

What I’ve been researching, in Python 2.x, the command input() "evaluates" the context in which the call was made. The following example:

>>> x = input()
"hello"
>>> y = input()
x + " world"
>>> y
'hello world'
  • "What’s the difference between raw_input ...?" -"The difference is that raw_input does not exist". ... I would say that is a very drastic difference!

  • But it failed to explain what the extinct input makes n Python2

0

raw_input() returns the value entered as string, while input() returns the value as integer Note: input() only accepts numbers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.