Python float Function Instance Usage

  • 2021-10-11 19:04:31
  • OfStack

We know that there are many types of numbers, such as integers and floating-point numbers. In the discussion of string values, we will need to use the form of floating-point values, so we need functions to transform them. This is the function of float function, which can convert the values. Below, we will introduce the 1 series of float function in detail.

1. Description

Given a string value (including floating-point values), we must convert it to a floating-point value in Python. To convert string values to float, we can use the float () function.

2. Grammar


class float([x])

3. Parameters

x--Integer or string

4. Return value

Returns a floating point number.

5. Examples


print(float(1))
print(float(15))
print(float(-15.3))
print(float('568')) # String 

Related articles: