+ 5

Please explain the output for print(abs(3+4j))

How output comes 5.0

27th Feb 2018, 10:29 PM
Ashwani Kumar
Ashwani Kumar - avatar
6 Answers
+ 29
Absolute value is actually the distance between a given number and 0. If you think of a complex number as a two-dimensional tuple (for real and imaginary parts, respectively), you have, let's say: 3 + 4i (or 3 + 4j in Python) Now, the distance is the square root of the sums of squares, so: √(3² + 4²) = √(9 + 16) = √(25) = 5.0
27th Feb 2018, 10:48 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 2
thanks kuba, nicely explained
27th Feb 2018, 10:50 PM
Ashwani Kumar
Ashwani Kumar - avatar
+ 1
In python j after a number makes the number imaginary, see more here: https://stackoverflow.com/questions/8370637/complex-numbers-usage-in-python
27th Feb 2018, 10:36 PM
Sergiu Panaite
Sergiu Panaite - avatar
+ 1
thanks
27th Feb 2018, 10:46 PM
Ashwani Kumar
Ashwani Kumar - avatar
+ 1
Thanks for answering
3rd May 2020, 5:43 PM
《A$# ☆ $ING#》
《A$# ☆ $ING#》 - avatar
+ 1
5.0 is the answer Well it worked for me atleast
4th May 2020, 9:28 AM
Ben
Ben - avatar