當前位置:首頁 » 編程語言 » pythonbuiltin

pythonbuiltin

發布時間: 2025-01-02 02:57:17

『壹』 python 中的int函數怎麼用

int()是Python的一個內部函數

Python系統幫助裡面是這么說的

[python] view plain

  • >>>help(int)

  • Helponclassintinmole__builtin__:

  • classint(object)

  • |int(x[,base])->integer

  • |

  • |,ifpossible.Afloatingpoint

  • |(thisdoesnotincludeastring

  • |!)Whenconvertingastring,use

  • |theoptionalbase.

  • |non-string.Ifbaseiszero,

  • |stringcontent.

  • |.

  • [python] view plain

  • >>>int(12.0)

  • 12

  • int()函數可以將一個數轉化為整數

    [python] view plain

  • >>>int('12',16)

  • 18

  • 這里有兩個地方要注意:1)12要以字元串的形式進行輸入,如果是帶參數base的話

    2)這里並不是將12轉換為16進制的數,而是說12就是一個16進制的數,int()函數將其用十進制數表示,如下

    [python] view plain

  • >>>int('0xa',16)

  • 10

  • >>>int('10',8)

  • 8

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:593
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:887
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:581
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:765
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:683
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:1012
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:254
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:113
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:805
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:712