Features which are given as part of a high-level language that can be implemented through a basic connection with statement definition are known as Built-in Functions in Python. Python offers a broad range of built-in functions which makes it more versatile, easy to use, and fast to develop. Due to this broad range of built-in functions, you can do more with less code.
Some of popular Built-in Functions in Python:
Functions
Description
Example
int()
Return an integer object constructed from a number or string x, or return 0 if no arguments are given
>>> int(’23’)
23
len()
Return the length (the number of items) of an object. The argument may be a
sequence (such as a string, bytes, tuple, list, or range)
or a collection (such as a dictionary, set, or frozen set).
>>>len([1,2,3,4,5])
5
reversed()
returns a reverse iterator
>>> for i in reversed([1,2,3,4,5]):
print(i,end=”, “)
5, 4, 3, 2, 1,
float()
Return a floating point number constructed from a number or string x.
If no argument is given, 0.0 is returned.
>>>float(‘+12.34’)
12.34
>>> float(123)
123.0
round()
Return number rounded to ndigits precision after the decimal point.
If ndigits is omitted or is None, it returns the nearest integer to its input.
>>> round(2.122345,3)
2.122
>>> round(12.32)
12
input()
Function reads a line from the input, converts it to a string, and returns it.
# Program to illustrate usage of Abs() function.
def FindAbsolute(x):
print("Absolute Value of Given Number is:",abs(x))
x = int(input("Enter the number:"))
FindAbsolute(x)
Output:
Enter the number:-90
Absolute Value of Given Number is: 90
bin()
Converts an integer number to a binary string counterpart prefixed with “0b “.
# Program to find hexadecimal value of a decimal.
number = int(input("Enter the Number:"))
print("Hexadecimal value of entered number is:",hex(number))
Output:
Enter the Number:90
Hexadecimal value of entered number is: 0x5a
range()
returns an iterator from a starting point to a end point with a specific step. It is most commonly used in looping with a FOR LOOP.
Syntax:
range(start,stop[, step])
Note: Stop is a mandatory argument. Start and Step are optional (Default value of start is 0 and step is 1).
# Program to illustrate Range function.
for i in range(1,10,3):
print(i)
Output:
1
4
7
min()
Return the smallest item in an iterable or the smallest of two or more arguments.
If one positional argument is provided, it should be an iterable. The smallest item in the iterable is returned. If two or more positional arguments are provided, the smallest of the positional arguments is returned.
# Program to illustrate min() function.
myList = [2,3,42,1]
print(min(myList))
print(min(33,44,22,12))
Output:
1
12
max()
Return the largest item in an iterable or the largest of two or more arguments.
If one positional argument is provided, it should be an iterable. The largest item in the iterable is returned. If two or more positional arguments are provided, the largest of the positional arguments is returned.
Login/Signup to comment