Python float() With Examples

In this tutorial we are going to learn about python float() function. In our previous tutorial we learned about Python Join.

Python float()

As the name says, python float() function returns a floating point number. It takes one parameter and that is optional. So the basic syntax of python float() function is;

 

Here, item can be string, integer or float. So the basic example about python float is given in the following code.

So, if you check the output, you will find

python-float

Python float() special parameters

As we said earlier, the parameter of float() function is optional. So if you print a blank float() function, what will it print?

Well, it will print 0.0 as output. Again you can define infinity value in float and also NaN (Not A Number) using this function. To do so, you just have to put a string containing inf or NaN as parameter. Here the following code will guide you about this.

And you will get output like this.

python-float-method

So, That’s all about Python float function. Hope that you learned well. For any further query, feel free to use the comment box below.

By admin

Leave a Reply

%d bloggers like this: