1)input()
python3.x中把 raw_input 和 input 都归结为 input()
所以全部用 input() 就好了
并且,input() , 输入后得到的是 str 类型 , 必要时要进行类型的强制转换
2)generator 中的 next()
python2.x 中 generator 的输出是 g.next()
python3.x 中generator 的输出是 next(g)
3)sorted:
Python 3.x 取消了 cmp 参数
所以要传入多个参数的函数时
就要使用functools中的cmp_to_key,即在开头加上
from functools import cmp_to_key
4)print() 的换行设置
python2.x中是加一个‘ ,’阻止换行
python3.x中是用 end=' ' , ‘ ’中还可以写上以什么字符结尾!!
5)redece()
reduce 把结果继续和序列的下一个元素做累积计算
其效果就是:
reduce(f,[x1, x2, x3, x4]) = f(f(f(x1, x2), x3), x4)
在Python 3里,reduce()函数已经被从全局名字空间里移除了,它现在被放置在fucntools模块里用的话要先引入:
>>> from functools import reduce
6)pip install PIL失败了怎么办?
改用:pip install pillow
然后就成功了:
7)/
python3.x中
10/3 = 3.33334
10//3 = 3
8)异常处理
python2.x:
except Exception, e:
python3.x:
except Exception as e: