Built-in Functions and Modules
Explore Python's built-in functions available throughout your code and discover essential modules like math, cmath, random, and decimal. Learn how to import and use these modules to perform advanced mathematical operations and random number generation, enhancing your programming skills.
We'll cover the following...
We'll cover the following...
Built-in functions
Python has many built-in functions that are always available in any part of the program. The print() function that we use to send output to the screen is a built-in function.
Help for any built-in function is available using help(function).
Built-in functions that are commonly used with numbers are:
abs(x) # returns absolute value of xpow(x, y) # returns value of x raised to ymin(x1, x2,...)# returns smallest argumentmax(x1, x2,...)# returns largest argumentdivmod(x, y) # returns a pair(x // y,x % y)round(x [,n]) # returns x rounded to n digits after .bin(x) # returns binary equivalent of xoct(x) # returns octal equivalent of xhex(x) # returns hexadecimal equivalent of x
Commonly used built-in functions
The following Python program shows how to use ...