exponentiation | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 3

exponentiation

why is the result of 2**5 is not float and 9**1/2 is float ? thanks in advance!!

28th Jun 2019, 8:34 PM
Yeabsira Yetagessu
Yeabsira Yetagessu - avatar
13 Respuestas
+ 7
In Python, when using the division operator (/) or doing division of any sort, you always get float, unless you explicitly convert it to a integer, Yeabsira Yetagessu . So 2**5 returns an integer (32) while 9**1/2 (9 to the power of 1 divided by 2) returns a float (4.5) Hope this helps ūüėä
28th Jun 2019, 8:49 PM
aceisace
aceisace - avatar
+ 1
In Python 3, when you do division the answer will always be a float, unless you do int(9**1/2). This code would evaluate to 4.
28th Jun 2019, 11:16 PM
Roxy
Roxy - avatar
+ 1
Doing a square root will always give a float, even when it would be an integer in the same way that doing a division will give a float even when that would be an integer. 4/2 gives 2.0 and not 2 and, in the same way 9**0.5 gives 3.0 and not 3.
28th Jun 2019, 11:46 PM
Russ
Russ - avatar
+ 1
What does it mean ** in python ?
26th Jul 2019, 9:38 AM
Moses ben raghda
Moses ben raghda - avatar
+ 1
When you square an integer with a float the answer becomes a float These three examples may help you out: 1:Integer * or / Float = Float 4 * or / 2.0 = 6.0 or 2.0 2:Integer * or / Integer = Integer 4 * or / 2 = 6 or 2 3:Float * or / Float = Float 4.0 * or / 2.0 = 6.0 or 2.0
26th Jul 2019, 9:51 AM
66:101:110:74:97:109:105:110
66:101:110:74:97:109:105:110 - avatar
0
while using(/) then u get float value
25th Jul 2019, 8:47 AM
jessy polinati
0
Yeabsira Yetagessu because if the power of the number is integer, the result must be integer. But if the power of the number is float, the result may be integer or float so compiler choice float and there are a different between 9**1/2 and 9**(1/2)
6th Aug 2019, 8:41 AM
Abdullah Ayman
Abdullah Ayman - avatar
0
If u don't want that float use this(//)
7th Aug 2019, 8:24 PM
Selva Kumar
Selva Kumar - avatar
0
x, x=4,7 y, y=x+7,x-7 Print(x, y) What is the output
4th Sep 2019, 7:14 AM
Poonam Singh
Poonam Singh - avatar
0
please tell me clearly what is the meaning ** or // in python, why we use double..... please explain it clearly
22nd Mar 2020, 1:06 PM
ashi
ashi - avatar
0
So I get mathematics, tho Exponentiation is grinding my gears.. like I don't get it..
23rd Mar 2021, 7:40 PM
chris
chris - avatar
0
chris check out the tutorials on YouTube, the might help you if you don't understand these
25th Mar 2021, 3:15 PM
66:101:110:74:97:109:105:110
66:101:110:74:97:109:105:110 - avatar
- 2
Why was $0.01 used for the code and not 1,000,000? print(0.01 * (2**30)) Why? Thank you.
26th May 2022, 6:47 PM
Moses A.
Moses A.  - avatar