0
Solved, but whatâs the logic?
What is the output of following code? n= [2, 3] n.insert(0** 3, 3 ** 0) print(n) Output: [1, 2, 3]
3 Answers
+ 7
0**3 is 0, 3**0 is 1
+ 2
G'day Evgeny Sergeev have you done some learning about exponentials?
When we multiply a number by it's self we can write that on paper as n²
n² is the same as n*n
If we multiply it by it's self twice we can write on paper nÂł
nÂł is the same as n*n*n
If we have nš that is the same as n
If we have nⰠthat is always equal to 1 (I just realised I don't have a good reason for that... Hold up, I'll Google it.) {Edit: it's tricky. they get there by cancelling exponents in a fraction. eg nš/nš =1 but can also be written as nš/nš = nš-š =1 https://en.m.wikipedia.org/wiki/Exponentiation#Zero_exponent}
Computers were not programmed to read the superscript (little numbers above the normal text) so we use a different way to tell the programming language we want an exponential. Python has a shortcut, you can use đn**eđ to say I want n multiplied by it's self e times.
Other languages need to import math and use pow() or similar. Python is great!
0
Lisa got confused on 3**0 = 3