python2 和 python3 的一些区别
python2与python3的区别
区别点 | python2 | python3 |
---|---|---|
write() | 可以直接写utf8内容 | 写utf8内容碰到:TypeError: write() argument must be str, not bytes解决方法:open(file, ‘wb’) |
super() | super(CLASS_NAME, self).method() | super().method() |
/ | 除法运算,结果取整数 | 除法运算,结果为浮点数,取证书使用“//” |
dict | has_key()可以用来查询是否存在某个键 | has_key()方法不存了,使用’key in dictionary’来查询(python2也支持该方法) |
python3的新特性
新特性 | 描述 | 参考 |
---|---|---|
@ | 矩阵乘法运算符,目前还没有定义built-in的矩阵数据类型 | PEP 465 - A dedicated infix operator for matrix multiplication |
/ | 除法运算,结果浮点数 | |
// | 除法运算,结果取整数 |