Divisions create float in python 3 then... Why float is used in >>>9**(1/2) that is 3.0 and >>>2**5 is 32 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Divisions create float in python 3 then... Why float is used in >>>9**(1/2) that is 3.0 and >>>2**5 is 32

In exponential operation >>>2**5 is 32 float not used but in >>>9**(1/2) is 3.0 float is used

14th Jul 2017, 6:21 AM
pratik ahir
pratik ahir - avatar
2 Answers
+ 2
Didn't the answer jump at you as you typed this question? :) Square root of 9 is 9**0.5. And once there is a float in an expression, it propagates all the way to the expression's final value. Thus 3.0.
14th Jul 2017, 6:25 AM
Venkatesh Pitta
Venkatesh Pitta - avatar
+ 2
Implicit variable typing: An integer elevated to the power of another integet is necessarly an integer, while an integer elevated to a power of 1/n will calculate the nth root of it, and will implicitly return a float type... as any float in a power expression ^^
14th Jul 2017, 6:29 AM
visph
visph - avatar