python函数示例
Python float()函数 (Python float() function)
float() function is a library function in Python, it is used to get a float value from a given number or a string. It accepts either a string (that should contain a number) or a number and returns float value.
float()函数是Python中的一个库函数,用于从给定数字或字符串中获取浮点值。 它接受一个字符串(应该包含一个数字)或一个数字,并返回浮点值。
Syntax:
句法:
float(value)
Parameter:value – string or number to be converted into float.
参数: value –要转换为float的字符串或数字。
Return value: float – returns a float value.
返回值: float-返回一个浮点值。
Example:
例:
Input:
val1 = "10.23"
val2 = "10"
val3 = 10
print(float(val1))
print(float(val2))
print(float(val3))
Output:
10.23
10.0
10.0
Python code to convert string or number into float
将字符串或数字转换为浮点数的Python代码
# python code to demonstrate an example
# of float() function
print(float("10.23")) # will return 10.23
print(float("10")) # will return 10.0
print(float(10)) # will return 10.0
print(float(10.23)) # will return 10.23
Output
输出量
10.23
10.0
10.0
10.23
翻译自: https://www.includehelp.com/python/float-function-with-example.aspx
python函数示例