Differences between input commands in Python 2.x and 3.x

user2820691

Ok, so i use a lot of input commands, and I understood that in Python2 I can do:

text = raw_input ('Text here')

But now that i use Python 3 I was wondering what's the difference between:

text = input('Text here')

and:

text = eval(input('Text here'))

when do I have to use the one or the other?

user2555451

In Python 3.x, raw_input became input and Python 2.x's input was removed. So, by doing this in 3.x:

text = input('Text here')

you are basically doing this in 2.x:

text = raw_input('Text here')

Doing this in 3.x:

text = eval(input('Text here'))

is the same as doing this in 2.x:

text = input('Text here')

Here is a quick summary from the Python Docs:

PEP 3111: raw_input() was 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()).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

read() differences between python 2 and python 3

From Dev

Differences between python 2 and 3 in terms of "translate"

From Dev

Differences between VNC and ssh -X

From Dev

Generator evaluation difference between Python 2.x and Python 3.x

From Dev

What are the differences between the Handlebars 1.x and 2.x APIs?

From Dev

Difference in multithreading overhead between python 2.x and 3.x

From Dev

Python3x Integer and String Input

From Dev

Differences between dd in Mac OS X and Linux

From Dev

Python: Eval with undefined variables (2*x+x = 3*x)

From Java

Why is 2 * x * x faster than 2 * ( x * x ) in Python 3.x, for integers?

From Dev

Why is 2 * x * x faster than 2 * ( x * x ) in Python 3.x, for integers?

From Dev

What are the differences between "-" and "--" in commands?

From Dev

AngularJS Scope differences between 1.0.x and 1.2.x

From Dev

Difference between x + x and 2*x in Java

From Dev

Script incompatibility for Python 2.x and Python 3.x

From Dev

Geocoding Strategies - Python 2.x to Python 3.x

From Dev

Python's Pickle differences between OS X and Linux (over Pandas DataFrame object)

From Dev

What are the differences between -perm /a+x, -perm /a=x, -perm -a=x and -perm -a+x with find?

From Dev

SOLR 4.x vs 3.x parsedquery differences

From Dev

Creating a 3x3 matrix with user input numbers in python

From Dev

(-6x^2-x-7)(2x^3+3x^2-2x-5) as input in SymPy

From Dev

Differences between GNOME 2 and GNOME 3

From Dev

Deal with buffer in Python 2.x and 3.x

From Dev

Regex unicode in python 2.x vs 3.x

From Dev

Deal with buffer in Python 2.x and 3.x

From Dev

Accessing Python2.x and 3.x in windows

From Dev

What's the difference between python3.<x> and python3.<x>m

From Dev

Python 3.x - Input only returns first item

From Dev

What was the reason for removing raw_input() in python 3.x?

Related Related

  1. 1

    read() differences between python 2 and python 3

  2. 2

    Differences between python 2 and 3 in terms of "translate"

  3. 3

    Differences between VNC and ssh -X

  4. 4

    Generator evaluation difference between Python 2.x and Python 3.x

  5. 5

    What are the differences between the Handlebars 1.x and 2.x APIs?

  6. 6

    Difference in multithreading overhead between python 2.x and 3.x

  7. 7

    Python3x Integer and String Input

  8. 8

    Differences between dd in Mac OS X and Linux

  9. 9

    Python: Eval with undefined variables (2*x+x = 3*x)

  10. 10

    Why is 2 * x * x faster than 2 * ( x * x ) in Python 3.x, for integers?

  11. 11

    Why is 2 * x * x faster than 2 * ( x * x ) in Python 3.x, for integers?

  12. 12

    What are the differences between "-" and "--" in commands?

  13. 13

    AngularJS Scope differences between 1.0.x and 1.2.x

  14. 14

    Difference between x + x and 2*x in Java

  15. 15

    Script incompatibility for Python 2.x and Python 3.x

  16. 16

    Geocoding Strategies - Python 2.x to Python 3.x

  17. 17

    Python's Pickle differences between OS X and Linux (over Pandas DataFrame object)

  18. 18

    What are the differences between -perm /a+x, -perm /a=x, -perm -a=x and -perm -a+x with find?

  19. 19

    SOLR 4.x vs 3.x parsedquery differences

  20. 20

    Creating a 3x3 matrix with user input numbers in python

  21. 21

    (-6x^2-x-7)(2x^3+3x^2-2x-5) as input in SymPy

  22. 22

    Differences between GNOME 2 and GNOME 3

  23. 23

    Deal with buffer in Python 2.x and 3.x

  24. 24

    Regex unicode in python 2.x vs 3.x

  25. 25

    Deal with buffer in Python 2.x and 3.x

  26. 26

    Accessing Python2.x and 3.x in windows

  27. 27

    What's the difference between python3.<x> and python3.<x>m

  28. 28

    Python 3.x - Input only returns first item

  29. 29

    What was the reason for removing raw_input() in python 3.x?

HotTag

Archive