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]

17th Mar 2022, 7:43 PM
Evgeny Sergeev
Evgeny Sergeev - avatar
3 Answers
+ 7
0**3 is 0, 3**0 is 1
17th Mar 2022, 7:47 PM
Lisa
Lisa - avatar
+ 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!
17th Mar 2022, 9:00 PM
HungryTradie
HungryTradie - avatar
0
Lisa got confused on 3**0 = 3
17th Mar 2022, 7:50 PM
Evgeny Sergeev
Evgeny Sergeev - avatar