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: