python - How does abs function work with this code : abs(3 + 4j)? - Stack Overflow
Differences in abs()
Where to find the abs() source code?
Here: https://github.com/python/cpython/blob/v3.8.0/Python/bltinmodule.c#L302
Which uses PyNumber_Absolute, which is here: https://github.com/python/cpython/blob/v3.8.0/Objects/abstract.c#L1236
Which usesnb_absolute which is implemented by whatever object is being used, e.g. for a float it is implemented here (there's mapping further up the code that redirects nb_absolute to float_abs): https://github.com/python/cpython/blob/v3.8.0/Objects/floatobject.c#L822
Which uses the c functions fabs: https://pubs.opengroup.org/onlinepubs/009695399/functions/fabs.html
Absolute value of an index in python
Videos
Because for complex numbers abs(number) will return magnitude of Complex Numbers.
Magnitude value will counted as : √x2+y2 = √(3² + 4²) = √(9 + 16) = √(25) = 5.0
So abs with complex number will return magnitude of complex numbers.
for further reference you can use https://www.geeksforgeeks.org/abs-in-python/.
As the rest of the answers stated above, 3+4j is a complex number and the formula of calculating the absolute value of a complex number x+yi is sqrt( (x^2) + (y^2) ). In your case it's:
sqrt(3^2 + 4^2) = sqrt(9 + 16) = sqrt(25) = 5