Python中int()函數(shù)的用法淺析
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
總結(jié)
以上所述是小編給大家介紹Python中int()函數(shù)的用法淺析,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
Pandas數(shù)據(jù)結(jié)構(gòu)之Series的使用
本文主要介紹了Pandas數(shù)據(jù)結(jié)構(gòu)之Series的使用,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-03-03在pycharm中debug 實時查看數(shù)據(jù)操作(交互式)
這篇文章主要介紹了在pycharm中debug 實時查看數(shù)據(jù)操作(交互式),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-06-06python實現(xiàn)去掉字符串中的\xa0、\t、\n
這篇文章主要介紹了python實現(xiàn)去掉字符串中的\xa0、\t、\n方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-08-08python matplotlib imshow熱圖坐標(biāo)替換/映射實例
這篇文章主要介紹了python matplotlib imshow熱圖坐標(biāo)替換/映射實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03