ScanSkill

abs

This hex() function returns the absolute value of a number.

Syntax

abs(number)

Here,

  • integer: Required. Any valid numeric expression.

Note: If the number is a complex number, its magnitude is returned. If the number is an integer with a base other than 10 the abs() function will return its value as a decimal integer.

Examples

  • Integer, float, complex numbers
>>> hex(100)
'0x64'
>>> hex(-30)
'-0x1e'
>>> hex(0b11)
'0x3'
>>> hex(0o67)
'0x37''
  • Numbers with a base value other than 10
>>> abs(0x10)
16
>>> abs(0b10)
2
>>> abs(0o20)
16