What does j in (3 + 4j) do? | Sololearn: Learn to code for FREE!


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 .

7/26/2018 11:48:44 AM


3 Answers

New Answer


"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.


"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-python


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!