The Python abs Function is an built-in function that returns the absolute value for a given number. In the case of a complex number, the absolute value is the magnitude of it’s real and imaginary parts.

### Syntax

The abs() Function takes a single number as a parameter. Number can either a float, integer or complex number.

``abs(number)``

#### Integer

The `abs()` function removes any negative sign that may be present on a negative integer.

```result = abs(5)
result = abs(-55)
```
``````#OUTPUT
5
55``````

#### Float

The `abs()` function removes any negative sign that may be present on a negative float number.

``````result = abs(5.4)
result = abs(-5.67)``````
``````#OUTPUT
5.4
5.67``````

#### Complex Number

The `abs()` function calculates the magnitude using the formula magnitude = `(Re^2 + Im^2)^1/2`. For this reason, negative signs do not have any effect on the output. Any negative sign is removed when the real and imaginary parts are squared.

```result = abs(3 + 4i)
result = abs(-3 - 4i)
```
``````#OUTPUT
5
5``````

This marks the end of the Python abs Function. Any suggestions or contributions for CodersLegacy are more than welcome. Questions can be asked in the comment section below.

Here’s a link back to the main Python Built-in Functions page.

Subscribe
Notify of
{"ft_lang_label":"__label__en","ft_lang_prob":0.719051,"math_prob":0.9949079,"size":1231,"snap":"2021-43-2021-49","text_gpt3_token_len":297,"char_repetition_ratio":0.15484923,"word_repetition_ratio":0.10526316,"special_character_ratio":0.24939074,"punctuation_ratio":0.08677686,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99658346,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-12-09T13:35:32Z\",\"WARC-Record-ID\":\"<urn:uuid:83799f32-f648-414c-9a98-fe97ff1cf109>\",\"Content-Length\":\"106283\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:92a252ac-30c5-408a-9276-5b57713a119d>\",\"WARC-Concurrent-To\":\"<urn:uuid:fecf35fd-65be-462e-ad24-c46daf17496f>\",\"WARC-IP-Address\":\"104.21.14.75\",\"WARC-Target-URI\":\"https://coderslegacy.com/python/python-built-in-functions/python-abs-function/\",\"WARC-Payload-Digest\":\"sha1:HDMG4WFFH2YPURVIVOGG6T64LOMUC6YR\",\"WARC-Block-Digest\":\"sha1:JXQXDY4F7QEMCLGJEFFEY6XN6KRTY3NY\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-49/CC-MAIN-2021-49_segments_1637964364169.99_warc_CC-MAIN-20211209122503-20211209152503-00517.warc.gz\"}"}