pow() function returns float or integer?
Today, someone posted this code and asked why x is float ?
>>> from math import pow >>> x = pow(5, 2) >>> x 25.0It's float because the pow function of math package returns float. But there is a built-in pow function in Python which will return integer in this case. You need to restart the python interpreter before you run the following code :
>>> a = 5 >>> x = pow(a, 2) >>> x 25 >>> type(x) <type 'int'>So, don't get confused. Happy coding! :)
Comments
>>> x = pow(5,2)
>>> x
25.0
>>> a = 5
>>> x = pow(a,2)
>>> x
25.0
>>> type(x)
This is my code but why returns float??
>>> a = 5
>>> x = pow(a, 2)
>>> x
25
>>> type(x)