Python round

This Python math function rounds the specified expression or number to the nearest integer, and the syntax of this is

round(Number, Digits);

If the number argument is a positive or negative number, the Python round function returns the nearest decimal number. And if it is not a number, it returns TypeError.

Digits (Optional): If you omit this argument, Python round function displays the number to the nearest integer value. Otherwise, the Number prints the nearest to the decimal number specified in the Digits arguments.

Python round Function Example

This math function rounds the number to the nearest integer. In this example, we are going to find the nearest values of different data types. In the first two, we used Python round function directly on both the Positive decimals and negative decimals.

Tup = (10.98, 20.26, 30.05, -40.95 , 50.85) # Tuple Declaration

Lis = [-10.98, 32.65, -39.29, -42.15, -39.97] # List Declaration

  • Next two statements, we used the round Function with two arguments, so they display the nearest decimal fractions in the third position.
  • Following four, we used this on Tuple and List items. If you observe the Python screenshot, this Math function is working correctly on them.
  • Then, We tried directly on multiple values.
  • Last, We tried on the String value, and it returns TypeError.
Python ROUND Function