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

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

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

6条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-21 04:45

    In Python 2, raw_input() returns a string, and input() tries to run the input as a Python expression.

    Since getting a string was almost always what you wanted, Python 3 does that with input(). As Sven says, if you ever want the old behaviour, eval(input()) works.

提交回复
热议问题