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

熱點內容
pythonrst 發布:2025-09-18 19:28:50 瀏覽:404
頁面訪問在線升級 發布:2025-09-18 19:13:46 瀏覽:773
相機存儲滿 發布:2025-09-18 19:12:19 瀏覽:754
如何搭載我的世界伺服器 發布:2025-09-18 19:02:39 瀏覽:426
c語言組框 發布:2025-09-18 19:02:23 瀏覽:942
如何看見真我手機的全部配置 發布:2025-09-18 18:48:10 瀏覽:975
戰地5默認是什麼伺服器 發布:2025-09-18 17:59:32 瀏覽:310
安卓變ios系統主題怎麼弄 發布:2025-09-18 17:54:07 瀏覽:889
linux出口ip 發布:2025-09-18 17:51:57 瀏覽:950
androidbitmap使用 發布:2025-09-18 17:49:20 瀏覽:244