Skip to content
This repository has been archived by the owner on Apr 1, 2021. It is now read-only.

Article: Python abs() #825

Merged
4 commits merged into from
Apr 30, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions python-abs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Python abs(x)

`abs()` is a built in function in Python 3, to compute the absolute value of any number. It takes one argument `x`. 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.
Copy link

@ghost ghost Apr 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"built in function in Python 3": Repetitive use of the word in.
Maybe change to: "built in function with Python 3".


## Argument
It takes one argument `x` - 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)

[Documentation](https://docs.python.org/3/library/functions.html#abs)