Comparing input functions

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

4 answers to this question.

+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
  2.  
  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
591 views
+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
• 58,090 points
779 views
+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
• 58,090 points
2,092 views
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
• 58,090 points
511 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,051 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
3,466 views
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
600 views
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
387 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP