René's URL Explorer Experiment


Title: How to Find an Absolute Value in Python – Real Python

Open Graph Title: How to Find an Absolute Value in Python – Real Python

Description: Learn how to calculate the Python absolute value with abs(), implement the math behind it from scratch, and customize it in your own classes.

Open Graph Description: Learn how to calculate the Python absolute value with abs(), implement the math behind it from scratch, and customize it in your own classes.

Mail addresses
?subject=Python article for you&body=How to Find an Absolute Value in Python on Real Python https://realpython.com/python-absolute-value/

Opengraph URL: https://realpython.com/python-absolute-value/

X: @realpython

direct link

Domain: realpython.com


Hey, it has json ld scripts:
{
  "@context": "http://schema.org",
  "@type": "Article",
  "headline": "How to Find an Absolute Value in Python",
  "image": {
    "@type": "ImageObject",
    "url": "https://files.realpython.com/media/How-to-Find-Absolute-Values-in-Python_Watermarked.8fd4b05b9475.jpg",
    "width": 1920,
    "height": 1080
  },
  "mainEntityOfPage": {
    "@type": "WebPage",
    "@id": "https://realpython.com/python-absolute-value/",
    "lastReviewed": "2025-06-04",
    "author": {
      "@type": "Person",
      "name": "Bartosz Zaczy\u0144ski",
      "image": "https://realpython.com/cdn-cgi/image/width=1694,height=1694,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/coders_lab_2109368.259b1599fbee.jpg",
      "url": "https://realpython.com/team/bzaczynski/",
      "affiliation": {
        "@type": "Organization",
        "@id": "https://realpython.com/#organization",
        "name": "Real Python",
        "url": "https://realpython.com",
        "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
      }
    },
    "reviewedBy": [
      {
        "@type": "Person",
        "name": "Aldren Santos",
        "image": "https://realpython.com/cdn-cgi/image/width=500,height=500,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/Aldren_Santos_Real_Python.6b0861d8b841.png",
        "url": "https://realpython.com/team/asantos/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Brenda Weleschuk",
        "image": "https://realpython.com/cdn-cgi/image/width=320,height=320,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/IMG_3324_1.50b309355fc1.jpg",
        "url": "https://realpython.com/team/bweleschuk/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Geir Arne Hjelle",
        "image": "https://realpython.com/cdn-cgi/image/width=800,height=800,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/gahjelle.470149ee709e.jpg",
        "url": "https://realpython.com/team/gahjelle/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Kate Finegan",
        "image": "https://realpython.com/cdn-cgi/image/width=400,height=400,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/VZxEtUor_400x400.7169c68e3950.jpg",
        "url": "https://realpython.com/team/kfinegan/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      }
    ]
  },
  "datePublished": "2025-06-04T14:00:00+00:00",
  "dateModified": "2025-06-04T14:09:22.989997+00:00",
  "publisher": {
    "@type": "Organization",
    "@id": "https://realpython.com/#organization",
    "name": "Real Python",
    "url": "https://realpython.com",
    "logo": {
      "@type": "ImageObject",
      "url": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png",
      "width": 512,
      "height": 512
    },
    "description": "Real Python is a leading provider of online Python education and one of the largest language-specific online communities for software developers. It publishes high-quality learning resources, such as tutorials, books, and courses to an audience of millions of developers, data scientists, and machine learning engineers each month.",
    "slogan": "Become a Python Expert",
    "email": "info@realpython.com",
    "sameAs": [
      "https://github.com/realpython",
      "https://www.youtube.com/realpython",
      "https://twitter.com/realpython",
      "https://x.com/realpython",
      "https://www.linkedin.com/company/realpython-com/",
      "https://www.facebook.com/learnrealpython",
      "https://www.instagram.com/realpython",
      "https://www.tiktok.com/@realpython.com"
    ]
  },
  "author": {
    "@type": "Person",
    "name": "Bartosz Zaczy\u0144ski",
    "image": "https://realpython.com/cdn-cgi/image/width=1694,height=1694,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/coders_lab_2109368.259b1599fbee.jpg",
    "url": "https://realpython.com/team/bzaczynski/",
    "affiliation": {
      "@type": "Organization",
      "@id": "https://realpython.com/#organization",
      "name": "Real Python",
      "url": "https://realpython.com",
      "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
    }
  },
  "description": "Learn how to calculate the Python absolute value with abs(), implement the math behind it from scratch, and customize it in your own classes.",
  "hasPart": {
    "@type": "FAQPage",
    "mainEntity": [
      {
        "@type": "Question",
        "name": "How do you find the absolute value of a number in Python?",
        "acceptedAnswer": {
          "@type": "Answer",
          "text": "

You can find the absolute value of a number in Python by using the built-in abs() function, which returns the magnitude of the number regardless of its sign.

" } }, { "@type": "Question", "name": "Can you find the absolute value of a complex number in Python?", "acceptedAnswer": { "@type": "Answer", "text": "

Yes, you can find the absolute value of a complex number in Python using the abs() function. This function calculates the magnitude of the complex number as a floating-point value.

" } }, { "@type": "Question", "name": "How can you calculate the absolute value of a list of numbers in Python?", "acceptedAnswer": { "@type": "Answer", "text": "

To calculate the absolute value of a list of numbers in Python, you can use a list comprehension or the map() function to apply abs() to each element in the list.

" } }, { "@type": "Question", "name": "How do you customize the behavior of abs() for a custom class in Python?", "acceptedAnswer": { "@type": "Answer", "text": "

You customize the behavior of abs() for a custom class by defining the .__abs__() method within the class, which allows you to specify how the absolute value should be calculated for instances of that class.

" } } ] } }

authorReal Python
twitter:cardsummary_large_image
twitter:imagehttps://files.realpython.com/media/How-to-Find-Absolute-Values-in-Python_Watermarked.8fd4b05b9475.jpg
og:imagehttps://files.realpython.com/media/How-to-Find-Absolute-Values-in-Python_Watermarked.8fd4b05b9475.jpg
twitter:creator@realpython
og:typearticle

Links:

https://realpython.com/
Start Herehttps://realpython.com/start-here/
Learn Python https://realpython.com/python-absolute-value
Python Tutorials →In-depth articles and video courseshttps://realpython.com/search?kind=article&kind=course&order=newest
Learning Paths →Guided study plans for accelerated learninghttps://realpython.com/learning-paths/
Quizzes & Exercises →Check your learning progresshttps://realpython.com/quizzes/
Browse Topics →Focus on a specific area or skill levelhttps://realpython.com/tutorials/all/
Community Chat →Learn with other Pythonistashttps://realpython.com/community/
Office Hours →Live Q&A calls with Python expertshttps://realpython.com/office-hours/
Podcast →Hear what’s new in the world of Pythonhttps://realpython.com/podcasts/rpp/
Books →Round out your knowledge and learn offlinehttps://realpython.com/products/books/
Reference →Concise definitions for common Python termshttps://realpython.com/ref/
Code Mentor →BetaPersonalized code assistance & learning toolshttps://realpython.com/mentor/
Unlock All Content →https://realpython.com/account/join/
More https://realpython.com/python-absolute-value
Learner Storieshttps://realpython.com/learner-stories/
Python Newsletterhttps://realpython.com/newsletter/
Python Job Boardhttps://www.pythonjobshq.com
Meet the Teamhttps://realpython.com/team/
Become a Tutorial Writerhttps://realpython.com/write-for-us/
Become a Video Instructorhttps://realpython.com/become-an-instructor/
Searchhttps://realpython.com/search
https://realpython.com/search
Joinhttps://realpython.com/account/join/
Sign‑Inhttps://realpython.com/account/login/?next=%2Fpython-absolute-value%2F
Browse Topicshttps://realpython.com/tutorials/all/
Guided Learning Pathshttps://realpython.com/learning-paths/
Basicshttps://realpython.com/search?level=basics
Intermediatehttps://realpython.com/search?level=intermediate
Advancedhttps://realpython.com/search?level=advanced
aihttps://realpython.com/tutorials/ai/
algorithmshttps://realpython.com/tutorials/algorithms/
apihttps://realpython.com/tutorials/api/
best-practiceshttps://realpython.com/tutorials/best-practices/
careerhttps://realpython.com/tutorials/career/
communityhttps://realpython.com/tutorials/community/
databaseshttps://realpython.com/tutorials/databases/
data-sciencehttps://realpython.com/tutorials/data-science/
data-structureshttps://realpython.com/tutorials/data-structures/
data-vizhttps://realpython.com/tutorials/data-viz/
devopshttps://realpython.com/tutorials/devops/
djangohttps://realpython.com/tutorials/django/
dockerhttps://realpython.com/tutorials/docker/
editorshttps://realpython.com/tutorials/editors/
flaskhttps://realpython.com/tutorials/flask/
front-endhttps://realpython.com/tutorials/front-end/
gamedevhttps://realpython.com/tutorials/gamedev/
guihttps://realpython.com/tutorials/gui/
machine-learninghttps://realpython.com/tutorials/machine-learning/
newshttps://realpython.com/tutorials/news/
numpyhttps://realpython.com/tutorials/numpy/
projectshttps://realpython.com/tutorials/projects/
pythonhttps://realpython.com/tutorials/python/
stdlibhttps://realpython.com/tutorials/stdlib/
testinghttps://realpython.com/tutorials/testing/
toolshttps://realpython.com/tutorials/tools/
web-devhttps://realpython.com/tutorials/web-dev/
web-scrapinghttps://realpython.com/tutorials/web-scraping/
Table of Contentshttps://realpython.com/python-absolute-value#toc
Defining the Absolute Valuehttps://realpython.com/python-absolute-value#defining-the-absolute-value
Implementing the Absolute Value Function in Pythonhttps://realpython.com/python-absolute-value#implementing-the-absolute-value-function-in-python
Using the Built-in abs() Function With Numbershttps://realpython.com/python-absolute-value#using-the-built-in-abs-function-with-numbers
Integers and Floating-Point Numbershttps://realpython.com/python-absolute-value#integers-and-floating-point-numbers
Complex Numbershttps://realpython.com/python-absolute-value#complex-numbers
Fractions and Decimalshttps://realpython.com/python-absolute-value#fractions-and-decimals
Calling abs() on Other Python Objectshttps://realpython.com/python-absolute-value#calling-abs-on-other-python-objects
NumPy Arrays and pandas Serieshttps://realpython.com/python-absolute-value#numpy-arrays-and-pandas-series
Your Very Own Data Typeshttps://realpython.com/python-absolute-value#your-very-own-data-types
Conclusionhttps://realpython.com/python-absolute-value#conclusion
Frequently Asked Questionshttps://realpython.com/python-absolute-value#frequently-asked-questions
https://realpython.com/feedback/survey/article/python-absolute-value/liked/?from=article-sidebar
https://realpython.com/feedback/survey/article/python-absolute-value/disliked/?from=article-sidebar
Bartosz Zaczyńskihttps://realpython.com/python-absolute-value#author
https://realpython.com/python-absolute-value#reader-comments
basicshttps://realpython.com/tutorials/basics/
pythonhttps://realpython.com/tutorials/python/
Defining the Absolute Valuehttps://realpython.com/python-absolute-value#defining-the-absolute-value
Implementing the Absolute Value Function in Pythonhttps://realpython.com/python-absolute-value#implementing-the-absolute-value-function-in-python
Using the Built-in abs() Function With Numbershttps://realpython.com/python-absolute-value#using-the-built-in-abs-function-with-numbers
Integers and Floating-Point Numbershttps://realpython.com/python-absolute-value#integers-and-floating-point-numbers
Complex Numbershttps://realpython.com/python-absolute-value#complex-numbers
Fractions and Decimalshttps://realpython.com/python-absolute-value#fractions-and-decimals
Calling abs() on Other Python Objectshttps://realpython.com/python-absolute-value#calling-abs-on-other-python-objects
NumPy Arrays and pandas Serieshttps://realpython.com/python-absolute-value#numpy-arrays-and-pandas-series
Your Very Own Data Typeshttps://realpython.com/python-absolute-value#your-very-own-data-types
Conclusionhttps://realpython.com/python-absolute-value#conclusion
Frequently Asked Questionshttps://realpython.com/python-absolute-value#frequently-asked-questions
Remove adshttps://realpython.com/account/join/
Click here to download the free sample codehttps://realpython.com/bonus/python-absolute-value-code/
https://realpython.com/quizzes/python-absolute-value/
How to Find an Absolute Value in Pythonhttps://realpython.com/quizzes/python-absolute-value/
https://realpython.com/python-absolute-value#defining-the-absolute-value
vectorhttps://en.wikipedia.org/wiki/Vector_(mathematics_and_physics)
Real numbershttps://en.wikipedia.org/wiki/Real_number
complex numbershttps://realpython.com/python-complex-numbers/
piecewise functionhttps://en.wikipedia.org/wiki/Piecewise
number linehttps://en.wikipedia.org/wiki/Number_line
https://files.realpython.com/media/plot_number_line.293268c27c16.jpg
velocityhttps://en.wikipedia.org/wiki/Velocity
speedhttps://en.wikipedia.org/wiki/Speed
list comprehensionhttps://realpython.com/list-comprehension-python/
Euclidean normhttps://en.wikipedia.org/wiki/Norm_(mathematics)#Euclidean_norm
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-absolute-value#implementing-the-absolute-value-function-in-python
conditional statementhttps://realpython.com/python-conditional-statements/
conditional expressionhttps://realpython.com/python-conditional-statements/#conditional-expressions-pythons-ternary-operator
max()https://realpython.com/python-min-and-max/
square root functionhttps://realpython.com/python-square-root-function/
power functionhttps://docs.python.org/3/library/functions.html#pow
import statementhttps://realpython.com/python-modules-packages/#the-import-statement
exponentiation operator (**)https://realpython.com/python-numbers/#exponents
𝑛th roothttps://en.wikipedia.org/wiki/Nth_root
floating-point numberhttps://realpython.com/python-numbers/#floating-point-numbers
integerhttps://realpython.com/python-numbers/#integers
Python stringhttps://realpython.com/python-strings/
https://realpython.com/python-absolute-value#using-the-built-in-abs-function-with-numbers
machine codehttps://en.wikipedia.org/wiki/Machine_code
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-absolute-value#integers-and-floating-point-numbers
built-in functionshttps://docs.python.org/3/library/functions.html
https://realpython.com/python-absolute-value#complex-numbers
complex numberhttps://realpython.com/python-complex-numbers/
https://files.realpython.com/media/complexn.580985f6c3a4.png
https://realpython.com/python-absolute-value#fractions-and-decimals
fractionshttps://realpython.com/python-fractions/
decimalshttps://realpython.com/python-rounding/#the-decimal-class
floating-point representation errorhttps://docs.python.org/3/tutorial/floatingpoint.html#representation-error
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-absolute-value#calling-abs-on-other-python-objects
Python’s map()https://realpython.com/python-map-function/
https://realpython.com/python-absolute-value#numpy-arrays-and-pandas-series
NumPyhttps://realpython.com/numpy-array-programming/
slicinghttps://realpython.com/python-lists-tuples/#modifying-multiple-list-values
pandashttps://realpython.com/pandas-python-explore-dataset/
DataFramehttps://realpython.com/pandas-dataframe/
Python dictionaryhttps://realpython.com/python-dicts/
calendarhttps://docs.python.org/3/library/calendar.html#module-calendar
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-absolute-value#your-very-own-data-types
C programming languagehttps://realpython.com/c-for-python-programmers/
fabs()https://pubs.opengroup.org/onlinepubs/000095399/functions/fabs.html
hypot()https://pubs.opengroup.org/onlinepubs/000095399/functions/hypot.html
.__abs__()https://docs.python.org/3/reference/datamodel.html#object.__abs__
special methodshttps://realpython.com/python-classes/#special-methods-and-protocols
Euclidean spacehttps://en.wikipedia.org/wiki/Euclidean_space
hypotenusehttps://en.wikipedia.org/wiki/Hypotenuse
variadic functionhttps://en.wikipedia.org/wiki/Variadic_function
https://realpython.com/python-absolute-value#conclusion
Click here to download the free sample codehttps://realpython.com/bonus/python-absolute-value-code/
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-absolute-value#frequently-asked-questions
https://realpython.com/quizzes/python-absolute-value/
How to Find an Absolute Value in Pythonhttps://realpython.com/quizzes/python-absolute-value/
https://realpython.com/feedback/survey/article/python-absolute-value/liked/?from=article-footer
https://realpython.com/feedback/survey/article/python-absolute-value/disliked/?from=article-footer
https://realpython.com/team/bzaczynski/
» More about Bartoszhttps://realpython.com/team/bzaczynski/
https://realpython.com/team/asantos/
Aldrenhttps://realpython.com/team/asantos/
https://realpython.com/team/bweleschuk/
Brendahttps://realpython.com/team/bweleschuk/
https://realpython.com/team/gahjelle/
Geir Arnehttps://realpython.com/team/gahjelle/
https://realpython.com/team/kfinegan/
Katehttps://realpython.com/team/kfinegan/
Level Up Your Python Skills »https://realpython.com/account/join/?utm_source=rp_article_footer&utm_content=python-absolute-value
Level Up Your Python Skills »https://realpython.com/account/join/?utm_source=rp_article_footer&utm_content=python-absolute-value
https://realpython.com/feedback/survey/article/python-absolute-value/liked/?from=article-comments
https://realpython.com/feedback/survey/article/python-absolute-value/disliked/?from=article-comments
LinkedInhttps://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Frealpython.com%2Fpython-absolute-value%2F
Twitterhttps://twitter.com/intent/tweet/?text=Interesting%20Python%20article%20on%20%40realpython%3A%20How%20to%20Find%20an%20Absolute%20Value%20in%20Python&url=https%3A%2F%2Frealpython.com%2Fpython-absolute-value%2F
Blueskyhttps://bsky.app/intent/compose?text=Interesting%20Python%20article%20on%20%40realpython.com%3A%20How%20to%20Find%20an%20Absolute%20Value%20in%20Python%20https%3A%2F%2Frealpython.com%2Fpython-absolute-value%2F
Facebookhttps://facebook.com/sharer/sharer.php?u=https%3A%2F%2Frealpython.com%2Fpython-absolute-value%2F
Get tips for asking good questionshttps://realpython.com/python-beginner-tips/#tip-9-ask-good-questions
get answers to common questions in our support portalhttps://support.realpython.com
Real Python Community Chathttps://realpython.com/community/
“Office Hours” Live Q&A Sessionhttps://realpython.com/office-hours/
basicshttps://realpython.com/tutorials/basics/
pythonhttps://realpython.com/tutorials/python/
Defining Your Own Python Functionhttps://realpython.com/defining-your-own-python-function/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=python-absolute-value
How to Properly Indent Python Codehttps://realpython.com/how-to-indent-in-python/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=python-absolute-value
https://realpython.com/account/signup/?intent=continue_reading&utm_source=rp&utm_medium=web&utm_campaign=rwn&utm_content=v1&next=%2Fpython-absolute-value%2F
Continue »https://realpython.com/account/signup/?intent=continue_reading&utm_source=rp&utm_medium=web&utm_campaign=rwn&utm_content=v1&next=%2Fpython-absolute-value%2F
Sign-Inhttps://realpython.com/account/login/?next=/python-absolute-value/
Start Herehttps://realpython.com/start-here/
Learning Resourceshttps://realpython.com/search
Code Mentorhttps://realpython.com/mentor/
Python Referencehttps://realpython.com/ref/
Python Cheat Sheethttps://realpython.com/cheatsheets/python/
Support Centerhttps://support.realpython.com/
Learning Pathshttps://realpython.com/learning-paths/
Quizzes & Exerciseshttps://realpython.com/quizzes/
Browse Topicshttps://realpython.com/tutorials/all/
Live Courseshttps://realpython.com/live/
Bookshttps://realpython.com/books/
Podcasthttps://realpython.com/podcasts/rpp/
Newsletterhttps://realpython.com/newsletter/
Community Chathttps://realpython.com/community/
Office Hourshttps://realpython.com/office-hours/
Learner Storieshttps://realpython.com/learner-stories/
Plans & Pricinghttps://realpython.com/account/join/
Team Planshttps://realpython.com/account/join-team/
For Businesshttps://realpython.com/account/join-team/inquiry/
For Schoolshttps://realpython.com/account/join-team/education-inquiry/
Reviewshttps://realpython.com/learner-stories/
About Ushttps://realpython.com/about/
Teamhttps://realpython.com/team/
Mission & Valueshttps://realpython.com/mission/
Editorial Guidelineshttps://realpython.com/editorial-guidelines/
Sponsorshipshttps://realpython.com/sponsorships/
Careershttps://realpython.workable.com
Press Kithttps://realpython.com/media-kit/
Merchhttps://realpython.com/merch
https://www.youtube.com/realpython
https://x.com/realpython
https://www.linkedin.com/company/realpython-com
https://www.facebook.com/LearnRealPython
https://github.com/realpython/
Privacy Policyhttps://realpython.com/privacy-policy/
Terms of Usehttps://realpython.com/terms/
Securityhttps://realpython.com/security/
Contacthttps://realpython.com/contact/
https://realpython.com/

Viewport: width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover

Robots: max-image-preview:large


URLs of crawlers that visited me.