區別一:print語法使用
Python2.7 print語法使用 >>> ; print "Hello Python"
Python3.7 print語法使用 >>> print("Hello Python")
範例:在Pyt機制 提示Did you mean print("Hello Python3.7")
print 換行與不換行區別
## python 2.7 print不換行使用","即可 python 3.7 print 不換行使用end=""差異二: raw_input()和input()
Python 2.7 raw_input() input() 都存在可用 raw_input()接收字串string input()接收數字/flot.##int/flot. Python 3.7 raw_input()不存在 只存在input() 兩者合併 接收任意格式回傳string
######################################################################################################## #### ###區別三: 函數cmp()#########python 2.7 cmp(x,y)函數用於比較2個對象,如果x < y 返回-1, 如果x == y 回傳0, 如果x > y 回傳1######python3.7 cmp()已經不存在了,如果你需要實作比較功能,需要引入operator 模組,適合任何物件###
<span class="pun">>>><span class="pln"> <span class="kwd">import<span class="pln"> <span class="kwd">operator<br/><span class="pln"><span class="pun">>>><span class="pln"> <span class="kwd">operator<span class="pun">.<span class="pln">eq<span class="pun">(<span class="str">'hello'<span class="pun">,<span class="pln"> <span class="str">'name'<span class="pun">);<br/><span class="pln"><span class="kwd">False<br/><span class="pln"><span class="pun">>>><span class="pln"> <span class="kwd">operator<span class="pun">.<span class="pln">eq<span class="pun">(<span class="str">'hello'<span class="pun">,<span class="pln"> <span class="str">'hello'<span class="pun">);<br/><span class="pln"><span class="kwd">True<br/></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
以上是python2.7和3.7的區別的詳細內容。更多資訊請關注PHP中文網其他相關文章!