Built-in functions are those functions that are pre-defined in the Python interpreter and you don't need to import any module to use them. These functions help to perform a wide variety of operations on strings, iterators, and numbers. For instance, the built-in functions like sum(), min(), and max() are used to simplify mathematical operations.
How to Use Built-in Function in Python?To use built-in functions in your code, simply call the specific function by passing the required parameter (if any) inside the parentheses. Since these functions are pre-defined, you don't need to import any module or package.
Example of Using Built-in FunctionsConsider the following example demonstrating the use of built-in functions in your code:
# Using print() and len() function text = "Tutorials Point" print(len(text)) # Prints 15
In the above example, we are using two built-in functions print() and len().
List of Python Built-in FunctionsAs of Python 3.12.2 version, the list of built-in functions is given below −
Built-in Mathematical FunctionsThere are some additional built-in functions that are used for performing only mathematical operations in Python, they are listed below −
Sr.No. Function & Description1
The abs() function returns the absolute value of x, i.e. the positive distance between x and zero.
2
The max() function returns the largest of its arguments or largest number from the iterable (list or tuple).
3
The function min() returns the smallest of its arguments i.e. the value closest to negative infinity, or smallest number from the iterable (list or tuple)
4
The pow() function returns x raised to y. It is equivalent to x**y. The function has third optional argument mod. If given, it returns (x**y) % mod value
5
round() is a built-in function in Python. It returns x rounded to n digits from the decimal point.
6
The sum() function returns the sum of all numeric items in any iterable (list or tuple). An optional start argument is 0 by default. If given, the numbers in the list are added to start value.
Advantages of Using Built-in FunctionsThe following are the advantages of using built-in functions:
While working with built-in functions, you may encounter errors and to handle those errors you can use the try-except blocks. This may help you identify the type of error and exceptions raised.
Can we extend the functionality of built-in functions?Yes, we can extend the functionality of built-in functions by using it with other methods and by applying your logic as per the need. However, it will not affect the pre-defined feature of the used function.
Can I create my built-in functions?No, you cannot create your built-in function. But, Python allows a user to create user-defined functions.
How do I use built-in functions?Using a built-in function is very simple, call it by its name followed by parentheses, and pass the required arguments inside the parentheses.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4