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

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

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

6条回答
  •  余生分开走
    2020-11-21 05:07

    If You want to ensure, that your code is running with python2 and python3, use function input () in your script and add this to begin of your script:

    from sys import version_info
    if version_info.major == 3:
        pass
    elif version_info.major == 2:
        try:
            input = raw_input
        except NameError:
            pass
    else:
        print ("Unknown python version - input function not safe")
    

提交回复
热议问题