+ 1
What does j in (3 + 4j) do?
I came across this challange: " What is the output of this code? print(abs(3 + 4j)) " output: 5.0 but I don't get what j does in this code and why the answer is 5.0 .
3 Respostas
+ 6
"j" (or also written as "i" sometimes) represents an imaginary number.
You can learn more about it by googling "Complex number" or "imaginary number".
https://en.wikipedia.org/wiki/Complex_number
To calculate the answer, see the wikipedia link above, and imagine to calculate the length of "blue arrow" in the figure at the right top page.
To simplify, you can imagine right triangle, with a leg a = 3 and another leg b = 4.
For output, you want to calculate another leg c, opposite to the right angle, using Pythagorean theorem (a^2 + b^2 = c^2)
The answer is sqrt(3^2 + 4^2) = 5.
Again, you may want to learn complex number to understand fully. Hope it helps.
+ 2
"j" is notation for a complex number, don't look to much into it if you don't know at least intermediate math
read on more on usage here
https://stackoverflow.com/questions/8370637/complex-numbers-usage-in-JUMP_LINK__&&__python__&&__JUMP_LINK
+ 1
Up until now, I've only had a basic introduction about the complex number, but I'll definitely look into it.
Thanks for helping me!