【320】Python 2.x 與 3.x 的區別

來源:互聯網
上載者:User

標籤:NPU   代碼   inter   proc   href   .net   bsp   targe   python3   

通過代碼移植的報錯進行梳理!

 

1. print 函數的區別

  Python 2.x 中可以加空格或者括弧,但是 Python 3.x 只能是括弧的

# Python 2.x>>> print "processing..."processing...>>> print("processing...")processing...# Python 3.x>>> print("processing...")processing...

 

2. raw_input 與 input 函數

  Python 2.x 中 raw_input 與 Python 3.x 中 input 函數類似,而 Python 2.x 中的 input 函數接收數字或者帶引號字串

# Python 2.x>>> a = raw_input("Value: ")Value: Alex>>> a‘Alex‘>>> b = input("Value: ")Value: "Alex">>> b‘Alex‘# Python 3.x>>> a = input("Value: ")Value: Alex>>> a‘Alex‘

參考:python2.x和python3.x中raw_input( )和input( )區別

 

3. Tkinter 模組

  Python 2.x 為 Tkinter,但是 Python 3.x 為 tkinter(小寫)

# Python 2.x>>> import Tkinter# Python 3.x>>> import tkinter

參考:Python GUI編程(Tkinter)

 

4. 除法運算子

  Python 2.x 中 /、// 均為整除,但是 Python 3.x 中 / 表示除以,// 表示整除

# Python 2.x>>> 77/601>>> 77//601# Python 3.x>>> 77/601.2833333333333334>>> int(77/60)1>>> 77//601

 

【320】Python 2.x 與 3.x 的區別

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.