新聞中心
Python中的函數(shù)有很多,之前我們有講過int()函數(shù),今天就具體用法給大家進行講解。

創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供圖們網(wǎng)站建設(shè)、圖們做網(wǎng)站、圖們網(wǎng)站設(shè)計、圖們網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、圖們企業(yè)網(wǎng)站模板建站服務(wù),十年圖們做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。
int()是Python的一個內(nèi)部函數(shù) ,Python系統(tǒng)幫助里面是這么說的。
>>> help(int)
Help on class int in module __builtin__:
class int(object)
| int(x[, base]) -> integer
|
| Convert a string or number to an integer, if possible. A floating point
| argument will be truncated towards zero (this does not include a string
| representation of a floating point number!) When converting a string, use
| the optional base. It is an error to supply a base when converting a
| non-string. If base is zero, the proper base is guessed based on the
| string content. If the argument is outside the integer range a
| long object will be returned instead.
>>> int(12.0)
12
int()函數(shù)可以將一個數(shù)轉(zhuǎn)化為整數(shù)
>>> int('12',16)
18
這里有兩個地方要注意:
1)12要以字符串的形式進行輸入,如果是帶參數(shù)base的話
2)這里并不是將12轉(zhuǎn)換為16進制的數(shù),而是說12就是一個16進制的數(shù),int()函數(shù)將其用十進制數(shù)表示,如下
>>> int('0xa',16)
10
>>> int('10',8)
8
對int()函數(shù)有遺忘的,可以查詢之前的文章進行知識回顧。更多Python學(xué)習(xí)推薦:PyThon學(xué)習(xí)網(wǎng)教學(xué)中心。
(推薦操作系統(tǒng):windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。)
名稱欄目:創(chuàng)新互聯(lián)Python教程:Python教程:int()函數(shù)的用法解析
當(dāng)前路徑:http://www.dlmjj.cn/article/cdjeieh.html


咨詢
建站咨詢
