python from __future__ import division,python__future_

來源:互聯網
上載者:User

python from __future__ import division,python__future_

1.在python2 中匯入未來的支援的語言特徵中division(精確除法),即from __future__ import division ,當我們在程式中沒有匯入該特徵時,"/"操作符執行的只能是整除,也就是取整數,只有當我們匯入division(精確演算法)以後,"/"執行的才是精確演算法。

如:

#python 2.7.6Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32Type "copyright", "credits" or "license()" for more information.#匯入前>>> 1/20>>> 10/33#匯入後>>> from __future__ import division>>> 1/20.5>>> 10/33.3333333333333335#匯入後如果要去整數,加'//'>>> 10//33

 2.但是在python3中已經支援了精確演算法,所以無需再匯入division(精確演算法):

如:

#python3.4.4Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 20:20:57) [MSC v.1600 64 bit (AMD64)] on win32Type "copyright", "credits" or "license()" for more information.>>> 1/20.5>>> 10/33.3333333333333335#如果需要取整數,加'//'>>> 10//33

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.