---
title: "abs"
space: "Student Handbook"
url: "https://portal.cs17.org/student-handbook/python-manual/built-in-functions/abs"
updated: "2026-10-05"
---

Returns how far a number is from zero.

## Synopsis

```python
abs(number)
```

## Description

`abs` removes the minus sign. It is useful for the distance between two numbers: `abs(a - b)`.

## Parameters

| Name | Meaning |
| --- | --- |
| `number` | An int or a float. |

## Return value

The same type of number, never negative.

## Example

```python
print(abs(-5))
print(abs(3.5))
print(abs(2 - 10))
```

It prints:

```text
5
3.5
8
```

## Common mistake

```python
n = input("Number: ")
print(abs(n))
```

Python stops with:

```text
Number: -5
TypeError: bad operand type for abs(): 'str'
```

`input` returns a string. Convert it first: `abs(int(n))`.

## See also

[int](/student-handbook/python-manual/built-in-functions/int), [min](/student-handbook/python-manual/built-in-functions/min), [max](/student-handbook/python-manual/built-in-functions/max)

[abs in the Python documentation](https://docs.python.org/3/library/functions.html#abs)
