Python float() 函數

Python 內置函數 Python 內置函數


描述

float() 函數用於將整數和字串轉換成浮點數。

語法

float()方法語法:

class float([x])

參數

  • x -- 整數或字串

返回值

返回浮點數。

實例

以下實例展示了 float() 的使用方法:

>>>float(1) 1.0 >>> float(112) 112.0 >>> float(-123.6) -123.6 >>> float('123') # 字串 123.0

Python 內置函數 Python 內置函數