回覆列表
  • 1 # 米哈關愛

    int()是Python的一個內部函式Python系統幫助裡面是這麼說的[python] view plain copy

    >>> 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. [python] view plain copy>>> int(12.0) 12 int()函式可以將一個數轉化為整數[python] view plain copy>>> int("12",16) 18 這裡有兩個地方要注意:1)12要以字串的形式進行輸入,如果是帶引數base的話2)這裡並不是將12轉換為16進位制的數,而是說12就是一個16進位制的數,int()函式將其用十進位制數表示,如下[python] view plain copy>>> int("0xa",16) 10 >>> int("10",8) 8

  • 中秋節和大豐收的關聯?
  • 如何用米酒發酵做饅頭?