+ 1
Can someone explain how ((3**2)//2) output is 4 ?
6 Antworten
+ 7
John Jeets
** is exponential operator
x**y here y is the power of x
so 3**2 = 3 * 3 = 9
// is known as floor division which returns whole integer (without fractional part) value not float
So 9 // 2 = 4
/ is known as normal division which returns float value
So 9 / 2 = 4.5
+ 5
3**2 = 3 * 3 = 9
9 / 2 = 4.5
9 // 2 = 4
+ 5
Thanks a lot zexu knub and A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟
+ 2
3**2 is equivalent to saying 3^2 as exponential so that gives 9 and 9//2 is floor division which ignores the decimal part say when you divide 9 by 2 your quotient is 4 and remainder is 1 but actually it's 4.5 so // here ignores. . 5
+ 1
// is floor division
+ 1
Python has things very similar to real life, which are, for example, the parentheses, now the ** sign is the expose; * is multiply; / is to divide, but, the result is a decimal expression; // is to divide, but, the result is a natural number; % is the remainder of the division; + is adding and - is subtracting.
Some examples:
print (2 ** 3)
Outcome:
8
print (2 * 3)
Outcome:
6
print (2/3)
Outcome:
0.6 ...
print (2 // 3)
Outcome:
0
print (2% 3)
Outcome:
2
print (2 + 3)
Outcome:
5
And subtracting would be -1.
Therefore, 3 ** 2 is 9 and 9 // 2 is 4; 4 by the // sign.
I hope it is of use to you, any questions, ask me.
Greetings.