Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Go Programs
    • Python Programs
    • Java Programs

Python round

by suresh

The Python round function rounds the specified expression or number to the nearest integer. The syntax of the round Function in Python Programming is

round(Number, Digits);

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

Digits (Optional): If you omit this argument, the round Function round the Number to the nearest integer value, otherwise, Number rounded to the decimal value specified in Digits arguments.

Python round Function Example

The math round function rounds the number to the nearest integer. In this example, we are going to round the values of different data types.

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

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

print('round() Function on Positive Decimal = %.2f' %round(10.98763))
print('round() Function on Negative Decimal = %.2f' %round(-15.48476))

print('round() Function with Second argument = %.3f' %round(10.98763, 3))
print('round() Function with Second argument = %.3f' %round(-15.48476, 3))

print('round() Function on Tuple Item = %d' %round(Tup[2]))
print('round() Function on Tuple Item = %d' %round(Tup[4]))
print('round() Function on List Item = %d' %round(Lis[2]))
print('round() Function on List Item = %d' %round(Lis[4]))

print('round() Function on Multiple Number = %.2f' %round(10 + 20 - 40.6578, 2))

print('round() Function on String Value = ', round('2.95'))
Python ROUND Function

Placed Under: Python

  • Download and Install Python
  • Python Arithmetic Operators
  • Python Assignment Operators
  • Python Bitwise Operators
  • Python Comparison Operators
  • Python Logical Operators
  • Python If Statement
  • Python If Else
  • Python Elif Statement
  • Python Nested If
  • Python For Loop
  • Python While Loop
  • Python Break
  • Python Continue
  • Python Dictionary
  • Python datetime
  • Python String
  • Python Set
  • Python Tuple
  • Python List
  • Python List Comprehensions
  • Python Lambda Function
  • Python Functions
  • Python Types of Functions
  • Python Iterator
  • Python File Handling
  • Python Directory
  • Python Class
  • Python classmethod
  • Python Inheritance
  • Python Method Overriding
  • Python Static Method
  • Connect Python and SQL Server
  • Python SQL Create DB
  • Python SQL Select Top
  • Python SQL Where Clause
  • Python SQL Order By
  • Python SQL Select Statement
  • Python len Function
  • Python max Function
  • Python map Function
  • Python print Function
  • Python sort Function
  • Python range Function
  • Python zip Function
  • Python Math Functions
  • Python String Functions
  • Python List Functions
  • Python NumPy Array
  • NumPy Aggregate Functions
  • NumPy Arithmetic Operations
  • Python Numpy Bitwise operators
  • Numpy Comparison Operators
  • Numpy Exponential Functions
  • Python Numpy logical operators
  • Python numpy String Functions
  • NumPy Trigonometric Functions
  • Python random Array
  • Python numpy concatenate
  • Python numpy Array shape
  • Python pandas DataFrame
  • Pandas DataFrame plot
  • Python Series
  • Python matplotlib Histogram
  • Python matplotlib Scatter Plot
  • Python matplotlib Pie Chart
  • Python matplotlib Bar Chart
  • Python List Length
  • Python sort List Function
  • Python String Concatenation
  • Python String Length
  • Python substring
  • Python Programming Examples

Copyright © 2021 · All Rights Reserved by Suresh

About Us | Contact Us | Privacy Policy