float()
float() returns floating point number by taking string or integer as input .
Here are some examples with different type of input numbers
print(float()) # 0.0
print(float(5)) # 5.0
print(float("34.5")) # 34.5
String inputs
print(float(" 45.8 ")) # 45.8
print(float("InF")) # inf
print(float("NaN")) #nan
print(float("Infinity"))#inf
We will get error message based on input
print(float('abc45'))
Output
ValueError: could not convert string to float: 'abc45'
Data type
We can check type of data by using type(). Here we have used one float number.
print(type(4.5)) # <class 'float'>
bin() int()
complex()
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com
plus2net.com