Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python2.7.3和Python3.3之间的区别_Python_Python 3.x - Fatal编程技术网

Python2.7.3和Python3.3之间的区别

Python2.7.3和Python3.3之间的区别,python,python-3.x,Python,Python 3.x,我在Python2.7.3中有以下python代码,我最近使用了一台新的笔记本电脑,它有Python3.3,我认为我不应该降级到Python2.7.3。代码是 :- 请告诉我应该做哪些更改,以便它可以轻松运行而不会出现任何错误。要使您的代码在Python 3中正常工作,请始终使用input()而不是raw\u input(),因为后者已不存在。另外,print语句已被print()函数替换。 Python 3中不存在原始输入(),请改用input(): str = input("enter ur

我在Python2.7.3中有以下python代码,我最近使用了一台新的笔记本电脑,它有Python3.3,我认为我不应该降级到Python2.7.3。代码是

:-


请告诉我应该做哪些更改,以便它可以轻松运行而不会出现任何错误。

要使您的代码在Python 3中正常工作,请始终使用
input()
而不是
raw\u input()
,因为后者已不存在。另外,
print
语句已被
print()
函数替换。

  • Python 3中不存在原始输入(),请改用
    input()

    str = input("enter ur text here: \n")
    
    s = eval(input("enter ur choice "))
    
  • input()
    不计算它在Python 3中解析的值,而是使用
    eval(input())

    str = input("enter ur text here: \n")
    
    s = eval(input("enter ur choice "))
    
  • print()
    是Python 3中的一个函数(它是Python 2中的一个语句),因此必须调用它:

    print("1.See the file\n")
    print("2.Exit\n")
    
    print(i)
    
    print("thank you ")
    
变成

input()
print()

变成

input()
print()

希望这能有所帮助,但是更多关于转换的信息可以在以下网址找到:)

有很多细微的差别。读这本书!