Comparing input functions

+1 vote
What is the difference between input() and raw_input() in Python?
Apr 16, 2018 in Python by zsche

4 answers to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
+1 vote
raw_input() has been discontinued in Python 3.x. However, in 2.x it returned the use input as a string while input() returned the use input as an expression.

In 3.x, input() performs the same function that raw_input() did in 2.x.
answered Apr 16, 2018 by Nietzsche's daemon
• 4,260 points
+1 vote

In python 2.x, raw_input() returns a string and input() evaluates the input in the execution context in which it is called

  1. >>> x = input()
  2. "hello"
  3. >>> y = input()
  4. x + " world"
  5. >>> y
  6. 'hello world'

In python 3.x, input has been scrapped and the function previously known as raw_input is now input. So you have to manually call compile and than eval if you want the old functionality.

  1. python2.x python3.x
  3. raw_input() --------------> input()
  4. input() -------------------> eval(input())

In 3.x, the above session goes like this

  1. >>> x = eval(input())
  2. 'hello'
  3. >>> y = eval(input())
  4. x + ' world'
  5. >>> y
  6. 'hello world'
  7. >>>

So you were probably getting an error at the interpretor because you weren't putting quotes around your input. This is necessary because it's evaluated.

answered Oct 18, 2018 by Nabarupa
+1 vote
  • raw_input() was renamed to input() so now input() returns the exact string.
  • Old input() was removed.

If you want to use the old input(), meaning you need to evaluate a user input as a python statement, you have to do it manually by using eval(input()).

answered Oct 18, 2018 by Nilesh
+1 vote
In Python raw_input() allows you to enter the inputs by manually in a automated Python Script, whereas input() contains automated host name or port number which can be modified, by editting the python using IDLE GUI Console.
answered Oct 18, 2018 by fuji

Related Questions In Python

0 votes
1 answer

Unable to take input from user in Python

num = input("enter number") print(num) READ MORE

answered May 1, 2018 in Python by aayushi
• 750 points
+1 vote
1 answer

How can I map input to output without using dynamic()

Here am talking about my example you ...READ MORE

answered Aug 8, 2018 in Python by Priyaj
• 56,100 points
+1 vote
1 answer

What is the difference between range and xrange functions in Python 2.X?

xrange only stores the range params and ...READ MORE

answered Aug 22, 2018 in Python by Priyaj
• 56,100 points
0 votes
1 answer

Comparing two files contents in python

Considering your file "Unique.txt" does just containt the IP ...READ MORE

answered Sep 11, 2018 in Python by Priyaj
• 56,100 points
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
+4 votes
6 answers
0 votes
1 answer

Comparing strings in Python

Convert both the strings to either uppercase ...READ MORE

answered May 28, 2018 in Python by Nietzsche's daemon
• 4,260 points
0 votes
1 answer

Enlarging a list using functions using append() and extend()

Let me illustrate this with an example ...READ MORE

answered Jun 1, 2018 in Python by Nietzsche's daemon
• 4,260 points

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.