TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

abs() in Python | Python abs() Function with Examples

abs() in Python | Python abs() Function with Examples on Python, Built in, Functions, abs Function, all Function, bin Function, bool Function, python Functions, new sum Function, bytes Function, new callable Function etc.

<< Back to PYTHON

Python abs() Function

The python abs() function is used to return absolute value of a number. It takes only one argument, a number whose absolute value is to be returned. The argument can be an integer and floating point number. If the argument is a complex number, then, abs() returns its magnitude.

Signature

  • abs (num)

Parameters

  • num - A number whose absolute value is to be returned. The number can be:
  1. integer
  2. floating number
  3. complex number

Return

It returns the absolute value of the specified number.

Python abs() Function Example 1

Let's see an example to get absolute value of a number.

#  integer number
integer = -40
print('Absolute value of -40 is:', abs(integer))

#  floating number
floating = -40.83
print('Absolute value of -40.83 is:', abs(floating))

Output:

Absolute value of -40 is: 40
Absolute value of -40.83 is: 40.83

Python abs() Function Example 2

This example shows magnitude of a complex number.

#complex number
complex = (3 - 4j)
print('Magnitude of 3 - 4j is:', abs(complex))

Output:

Magnitude of 3 - 4j is: 5.0





Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf