This repository has been archived by the owner on Apr 1, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
18 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Python abs() | ||
|
||
`abs()` is a built in function in Python 3, to compute the absolute value of any number. The argument can even be a [complex number](https://docs.python.org/3.0/library/cmath.html), and in that case its [modulus](http://www.mathcentre.ac.uk/resources/sigma%20complex%20number%20leaflets/sigma-complex9-2009-1.pdf) is returned. | ||
|
||
## Argument | ||
It takes one argument `num` - an integer, or decimal, or a complex number. | ||
|
||
## Return Value | ||
The return value would be a positive number. Even if complex number is passed, it would return its magnitude, computed as per complex number algebra. | ||
|
||
## Code Sample | ||
|
||
```python | ||
print(abs(3.4)) # prints 3.4 | ||
print(abs(-6)) # prints 6 | ||
print(abs(3 + 4j)) # prints 5, because |3 + 4j| = 5 | ||
``` | ||
:rocket: [REPL It!](https://repl.it/CL8k/0) |