Prime #### Prepinsta Prime

Video courses for company/skill based Preparation

(Check all courses)
Get Prime Video
Prime #### Prepinsta Prime

Purchase mock tests for company/skill building

(Check all mocks)
Get Prime mock

# Built-in Functions in Python

## What are Built-in functions?

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:

FunctionsDescriptionExample
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.

>>> input()
asdf
‘asdf’

sorted()Return a new sorted list from the items in iterable.>>> sorted([1,4,6,3,2,8,4])
[1, 2, 3, 4, 4, 6, 8]
str()Return a str version of object.>>> str(123)
‘123’ ## Use of Some Important Built-in Functions in Python:

### abs()

Return the absolute value of a number( An absolute numbers is the magnitude of real number without regard to its sign).

Syntax:
>>>abs(X)

```# 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:-90Absolute Value of Given Number is: 90`

### hex()

Converts an integer number to a hexadecimal lowercase string prefixed with “0x”.

Syntax:

>>>hex(x)

Note: oct() is used same as bin() and hex() to represent decimal in octal number system.

```# 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:90Hexadecimal value of entered number is: 0x5a`

### 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.

Syntax:

>>>min(iterable)

>>>min(arg1, arg2 ,…..)

```# Program to illustrate min() function.
myList = [2,3,42,1]
print(min(myList))
print(min(33,44,22,12))
```
```Output:
1
12```

### bin()

Converts an integer number to a binary string counterpart prefixed with “0b “.

Syntax:
>>> bin(x)

```# Program to find Binary value of a decimal.

number = int(input("Enter the Number:"))
print("Binary value of entered number is:",bin(number))```
```Output:
Enter the Number:14
Binary value of entered number is: 0b1110```

### 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:147`

### 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.

Syntax:

>>>max(iterable)

>>>max(arg1, arg2 ,…..)

```# Program to illustrate max() function.
myList = [2,3,42,1]
print(max(myList))
print(max(33,44,22,12))
```
```Output:
42
44```

#### How many built-in functions are there in python ?

There are a lot of built in functions in python as compared to other programming languages which make it do more in less code.

#### what is a library function?

A Library is  collection of built-in functions which are ready to use functions with a specific behavior. We can use these functions as per our need in any of our program to make some complex codes easier.

In short,  Built-in functions are also reffered as library functions.

#### What are ___....___ functions?

In Python we use some library functions which starts and end with Double-Underscore(__). These types of names are given to built-in functions in python only to avoid conflict between built-in functions and user defined function names.

#### How to define a function in python ?

To define a Function on your own you need to take care of following :

• Give your function a name followed by def keyword with trailing parenthesis ‘ ()’
• The arguments required to call your function must be specified within this parenthesis
• After parenthesis you’ve to place a colon(:) which starts the body of your function where you write the whole logic to be performed by function