Abs() and Round() in Python | Python for Data Science |Day 10

Hello, Python gang!
The Data Monk is back with a new agenda for today. Let’s stick to the abs() and round() in Python functions for the discussion today. The two functions, abs() and round() in Python are used in the mathematical aspects of Python. They are very easy to understand. Just follow along as we hop on our journey. 

  • abs()

As you must have guessed already from the meme, the absolute value of a number is the modulus of a number, which implies that it can never be negative. 

In Python, we use the abs() function to find the modulus of integers, floating point numbers and even complex numbers. 

Please open your IDEs or notebooks to try the lines of code below and compare your outputs with ours:

Positive integer:

Abs() and Round() in Python

Positive float number:

Negative integer:

Abs() and Round() in Python

Negative float number:

Complex number:

For the last line of code, the absolute value of the complex number is taken as its magnitude.

z = a + ib

i.e. square root of a and b.

  • Round() 

The round() function rounds the given number to the specified number of digits and   returns a float number.

We can also specify the number of digits upto which it should be rounded. Look at the line of code below:

Attempt the questions below to understand abs() and round(). You can also refer to https://www.geeksforgeeks.org/abs-in-python/ for the functions.

Do practice these questions on your own before seeking aid from our provided solutions. 

Alright, Pyfam. That’s the end of this tutorial. We will be back with another interesting topic. Stay with us for the rest of the series. Happy coding!

The Data Monk Interview Books – Don’t Miss

Now we are also available on our website where you can directly download the PDF of the topic you are interested in. At Amazon, each book costs ~299, on our website we have put it at a 60-80% discount. There are ~4000 solved interview questions prepared for you.

10 e-book bundle with 1400 interview questions spread across SQL, Python, Statistics, Case Studies, and Machine Learning Algorithms – Ideal for 0-3 years experienced candidates

23 E-book with ~2000 interview questions spread across AWS, SQL, Python, 10+ ML algorithms, MS Excel, and Case Studies – Complete Package for someone between 0 to 8 years of experience (The above 10 e-book bundle has a completely different set of e-books)

12 E-books for 12 Machine Learning algorithms with 1000+ interview questions – For those candidates who want to include any Machine Learning Algorithm in their resume and to learn/revise the important concepts. These 12 e-books are a part of the 23 e-book package

Individual 50+ e-books on separate topics

Important Resources to crack interviews (Mostly Free)

There are a few things which might be very useful for your preparation

The Data Monk Youtube channel – Here you will get only those videos that are asked in interviews for Data Analysts, Data Scientists, Machine Learning Engineers, Business Intelligence Engineers, Analytics Manager, etc.
Go through the watchlist which makes you uncomfortable:-

All the list of 200 videos
Complete Python Playlist for Data Science
Company-wise Data Science Interview Questions – Must Watch
All important Machine Learning Algorithm with code in Python
Complete Python Numpy Playlist
Complete Python Pandas Playlist
SQL Complete Playlist
Case Study and Guesstimates Complete Playlist
Complete Playlist of Statistics

Author: TheDataMonk

I am the Co-Founder of The Data Monk. I have a total of 6+ years of analytics experience 3+ years at Mu Sigma 2 years at OYO 1 year and counting at The Data Monk I am an active trader and a logically sarcastic idiot :)