Mathemetical Functions
Python provides a set of built-in functions that are always available for use. These functions perform common tasks and operations, simplifying coding and reducing the need to write repetitive code. Built-in functions cover a range of functionalities, from mathematical operations to type conversions.
Mathematical Functions
abs()
Returns the absolute value of a number.
Syntax:
abs(number)
Example:
print(abs(-5)) # Output: 5
pow()
Returns the power of a number, optionally with a modulus.
Syntax:
pow(base, exp[, mod])
Example:
print(pow(2, 3)) # Output: 8
print(pow(2, 3, 5)) # Output: 3
round()
Rounds a floating-point number to a specified number of decimal places.
Syntax:
round(number[, ndigits])
Example:
print(round(3.14159, 2)) # Output: 3.14