Functions in Python are the reason why many operations are so seamlessly performed and why this language is highly preferred over other programming languages. In general, there are two types of functions in Python: Built-in and User-defined functions. We will explore User-Defined functions in a separate article.
Built-in functions are those which are already available in Python library or can be used by importing or installing different modules into the Python IDE. The simplest example of a Built-in function is “print()” which displays output in a variety of formats. By default, if you are using Python 3.x, you will be able to use a variety of built-in functions in your program.
Let us look at some important Built-in functions in Python:
- input(): To get any value from the user in the IDE, you need to use the input function. By default, the returned data-type is a string which can be converted to an integer or float using any of the listed functions below.
- abs(): This built-in function is used to return the absolute value of an integer entered within the brackets.
- type(): More often than not, you will want to know the type of the variables being used in your program for various debugging purposes. The type() function is simply used to return the datatype of a variable in Python.
- floor(): This function is listed in the math library of Python and it is used to round the number to the next minimum and remove any decimal places.
- str(): This function is used to convert the given expression into a string.
- int(): This function is used to convert the given expression into an integer.
- random(): This function is used to return a value between 0 and 1.
- randint(): This function is used to return an integer value between any specified range
- sort(): By default, Python offers you a function which can sort a list based on ascending or descending order
- ord(): This function is used to return the ASCII or Unicode value of any character input. It is especially useful if you intend to encode or encrypt your numbers in a very simple way.
- len(): This function is used to find the length of an array in Python
- range(): This function is mostly used in a for loop, it is used to specify a range of numbers say from 0 to 1000 on which a specific variable will traverse.
- min(): If you want to know about the smallest element in your array, you will be using this function. Likewise, you will use max() to find the largest element in an array or iterable.
Let us take a brief look at how some of those functions above can be used to make a simple program:
print(“The following program prints highest and lowest values”) a = int(input(“Specify the number of values”) array =  for i in range(0,a): array.append(int(input(“Enter a number”)) print(“Lowest value is: “, min(array)) print(“Highest value is: “, max(array))
And that above is a simple example of how you can use built-in functions in Python rather than writing a lot of code separately for simple operations.
Do you have any important built-in function to share? Let us know in the comments section below!