當前位置:首頁 » 編程語言 » 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

熱點內容
取隨機數php 發布:2025-07-12 12:58:16 瀏覽:840
如何配置組合音響 發布:2025-07-12 12:53:54 瀏覽:93
c語言冪計算 發布:2025-07-12 12:52:36 瀏覽:566
兔費WLAN密碼多少 發布:2025-07-12 12:50:59 瀏覽:861
阿里雲分布式存儲 發布:2025-07-12 12:45:04 瀏覽:535
sql日誌壓縮 發布:2025-07-12 12:39:53 瀏覽:343
紅點角標演算法 發布:2025-07-12 12:11:16 瀏覽:844
開心消消樂伺服器繁忙什麼情況 發布:2025-07-12 12:11:14 瀏覽:239
資料庫的封鎖協議 發布:2025-07-12 12:10:35 瀏覽:725
如何配置一台長久耐用的電腦 發布:2025-07-12 11:43:03 瀏覽:602