int()是Python的一個(gè)內(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ù)可以將一個(gè)數(shù)轉(zhuǎn)化為整數(shù)
>>> int('12',16) 18 這里有兩個(gè)地方要注意:1)12要以字符串的形式進(jìn)行輸入,如果是帶參數(shù)base的話
2)這里并不是將12轉(zhuǎn)換為16進(jìn)制的數(shù),而是說12就是一個(gè)16進(jìn)制的數(shù),int()函數(shù)將其用十進(jìn)制數(shù)表示,如下
>>> int('0xa',16) 10 >>> int('10',8) 8 總結(jié)
以上所述是小編給大家介紹Python中int()函數(shù)的用法淺析,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時(shí)回復(fù)大家的。在此也非常感謝大家對武林站長站網(wǎng)站的支持!
新聞熱點(diǎn)
疑難解答
圖片精選