python如何选择python版本?
Python3.7已经发布了,目前Python的用户,主要使用的版本应该是Python3.6和Python2.7,那么是不是该转到Python3.7呢?
首先大家要知道Python3.7是对Python3.6的升级。Python官方对3.7的新特性描述链接如下:
https://docs.python.org/3/whatsnew/3.7.html
我们最需要注意的是相对于3.6来说,3.7在语法上几乎是完全兼容,除了如下这一点:
Backwardsincompatiblesyntaxchanges:
asyncandawaitarenowreservedkeywords.
这段话,指出了3.7的唯一不兼容3.6的地方就是async和await变成了Python语言中保留的关键字了。
什么意思?
就是async和await这两个词就像import,for,while这些词一样,是系统保留特殊用途的关键字。
也就是说在Python3.7里面你不能使用定义变量、函数之类的名字
比如,我像下面这样定义变量和函数:
async=1
defawait():
pass
使用Python3.6运行,没有问题,而在Python3.7里面就会报如下错误
SyntaxError:invalidsyntax
如何选择?
所以,如果项目目前使用的是Python3.6,而且项目又比较大的话,个人建议不用太着急转到3.7上去。因为不知道你的项目代码和依赖的第三方库的代码是不是做过3.7的兼容性测试,毕竟3.7刚刚出来不久。
3.7的pip执行
pipinstallpsycopg2-binary
安装就会失败,提示Error:pg_configexecutablenotfound,而3.6的pip安装就没有问题。
所以,我们最好等到3.7被普遍使用了,再转过去。
现在要转到Python3.7,除非有你们项目特别渴望使用的Python3.7里面的新特性。如果是那样的话,一定要做一个对老的代码覆盖比较充分的测试,防止上线运行的时候出现问题。
以上内容为大家介绍了Python培训之如何选择python版本?,希望对大家有所帮助,如果想要了解更多Python相关知识,请关注IT培训机构:千锋教育。

相关推荐HOT
更多>>
python正则表达式中的零宽断言
python正则表达式中的零宽断言1、概念有些元字符不匹配任何字符,只是简单的表示成功或失败,所以这些字符也叫零宽断言。2、符号举例(1)|或操作...详情>>
2023-11-14 11:35:03
python方法的绑定和未绑定
python方法的绑定和未绑定1、说明未绑定对象的方法:无self参数的方法,通过定义类调用函数,返回未绑定self的方法。绑定对象的方法:带self参...详情>>
2023-11-14 09:53:02
python海象运算符的使用
python海象运算符的使用1、在判断条件下允许操作。在一定程度上简化了代码,但降低了可读性。i=len((l:=[1,2,3]))#先对l进行赋值,在对i赋值whi...详情>>
2023-11-14 02:38:21
pythonelif语句报错是什么原因
python的else和elif语句也可以叫做子句,因为它们不能独立使用,两者都是出现在if、for、while语句内部的。else子句可以增加一种选择;而elif子...详情>>
2023-11-13 21:46:35热门推荐
技术干货






