What's the difference between `raw_input()` and `input()` in Python 3?

后端 未结 6 1973
执笔经年
执笔经年 2020-11-21 04:19

What is the difference between raw_input() and input() in Python 3?

6条回答
  •  轮回少年
    2020-11-21 04:46

    Python 2:

    • raw_input() takes exactly what the user typed and passes it back as a string.

    • input() first takes the raw_input() and then performs an eval() on it as well.

    The main difference is that input() expects a syntactically correct python statement where raw_input() does not.

    Python 3:

    • 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()).

提交回复
热议问题