Python built-in functions are pre-defined functions that come bundled with Python and can be used directly in a Python program without importing external libraries. They provide essential and commonly used functionality for various tasks, such as data type conversion, mathematical operations, string manipulation, file operations, etc. Here are the most commonly used 15 python built-in functions!

This article was published as a part of theÂ Data Science Blogathon.

- Top 15 Python Built-in Functions
- 1. print( ) function
- 2. type( ) function
- 3. input( ) function
- 4. abs( ) function
- 5. pow( ) function
- 6. dir( ) function
- 7. sorted( ) function
- 8. max( ) function
- 9. round( ) function
- 10. divmod( ) function
- 11. id( ) function
- 12. ord( ) function
- 13. len( ) function
- 14. sum( ) function
- 15. help( ) function
- End Notes
- Frequently Asked Questions

The built-in Python Functions which we are going to discuss in this article are as follows:

Function | Example | Description |
---|---|---|

`print()` | `print("Hello, World!")` | Prints output to the console |

`len()` | `len("Python")` | Returns the length of a string |

`range()` | `range(0, 10)` | Generates a range of integers from 0 to 9 |

`str()` | `str(123)` | Converts the integer value to a string |

`int()` | `int("123")` | Converts the string value to an integer |

`float()` | `float(123)` | Converts the integer value to a floating-point number |

`max()` | `max(1, 2, 3, 4, 5)` | Returns the maximum value in the list of numbers |

`min()` | `min(1, 2, 3, 4, 5)` | Returns the minimum value in the list of numbers |

`sorted()` | `sorted([3, 2, 1])` | Sorts the list in ascending order |

`type()` | `type("Python")` | Returns the type of the object as “str” |

`input()` | `name = input("Enter your name: ")` | Gets user input from the console and assigns it to a variable |

`sum()` | `sum([1, 2, 3, 4, 5])` | Returns the sum of all elements in the list |

`abs()` | `abs(-10)` | Returns the absolute value of the number |

`round()` | `round(3.14159, 2)` | Rounds the number to 2 decimal places |

`chr()` | `chr(65)` | Returns the character corresponding to the ASCII code 65, which is “A” |

Now, let’s discuss each of the above functions one-by-one with some examples:

The print() function prints the specified message to the screen or another standard output device.

The message that wants to print can be a string or any other object. This function converts the object into a string before written to the screen.

print("Analytics Vidhya is the Largest Data Science Community over whole world")

**Output:**

Analytics Vidhya is the Largest Data Science Community over whole world

print("Analytics Vidhya", "Chirag Goyal", "Data Scientist", "Machine Learning")

__Output:__

Analytics Vidhya Chirag Goyal Data Scientist Machine Learning

The type() function returns the type of the specified object.

list_of_fruits = ('apple', 'banana', 'cherry', 'mango') print(type(list_of_fruits))

__Output:__

<class 'tuple'>

variable_1 = "Analytics Vidhya" variable_2 = 105 print(type(variable_1)) print(type(variable_2))

__Output:__

<class 'str'> <class 'int'>

The input() function allows taking the input from the user.

a = input('Enter your name:') print('Hello, ' + a + ' to Analytics Vidhya')

__Output:__

Enter your name:Chirag Goyal Hello, Chirag Goyal to Analytics Vidhya

The abs() function returns the absolute value of the specified number.

negative_number = -676 print(abs(negative_number))

__Output:__

676

complex_number = 3+5j print(abs(complex_number))

__Output:__

5.830951894845301

The absolute value of a complex number is defined in the following way:

Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Image Source: **Link**

The pow() function returns the calculated value of x to the power of y i.e, x^{y}.

If a third parameter is present in this function, then it returns x to the power of y, modulus z.

x = pow(3, 4) print(x)

__Output:__

81

x = pow(3, 4, 5) print(x)

__Output:__

1

The dir() function returns all the properties and methods of the specified object, without the values.

This function even returns built-in properties which are the default for all objects.

class Person: name = "Chirag Goyal" age = 19 country = "India" education = "IIT Jodhpur" print(dir(Person))

__Output:__

The sorted() function returns a sorted list of the specified iterable object.

You can specify the order to be either ascending or descending. In this function, Strings are sorted alphabetically, and numbers are sorted numerically.

**NOTE: **If a list contains BOTH string values AND numeric values, then we cannot sort it.

tuple = ("h", "b", "a", "c", "f", "d", "e", "g") print(sorted(tuple))

__Output:__

['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']

tuple = ("h", "b", "a", "c", "f", "d", "e", "g") print(sorted(tuple, reverse=True))

__Output:__

['h', 'g', 'f', 'e', 'd', 'c', 'b', 'a']

The max() function returns the item with the maximum value or the item with the maximum value in an iterable.

If the values this function takes are strings, then it is done using an alphabetical comparison.

names_tuple = ('Chirag', 'Kshitiz', 'Dinesh', 'Kartik') print(max(names_tuple))

__Output:__

Kshitiz

number_tuple = (2785, 545, -987, 1239, 453) print(max(number_tuple))

__Output:__

2785

The round() function returns a floating-point number that is a rounded version of the specified number, with the specified number of decimals.

The default number of decimals is 0, meaning that the function will return the nearest integer.

nearest_number = round(87.76432) print(nearest_number)

__Output:__

88

nearest_number = round(-87.76432) print(nearest_number)

__Output:__

-88

nearest_number = round(87.46432) print(nearest_number)

__Output:__

87

The divmod() function returns a tuple containing the quotient and the remainder when the first argument i.e, the dividend is divided by the second argument i.e, the divisor.

x = divmod(7, 3) print(x)

__Output:__

(2, 1)

x = divmod(72, 6) print(x)

__Output:__

(12, 0)

The id() function returns a unique id for the specified object. Note that all the objects in Python have their own unique id.

The id is assigned to the object when it is created.

The id is the object’s memory address and will be different for each time you run the program. (except for some object that has a constant unique id, like integers from -5 to 256)

names_tuple = ('Chirag', 'Kshitiz', 'Dinesh', 'Kartik') print(id(names_tuple))

__Output:__

140727154106096

string = "Analytics Vidhya is the Largest Data Science Community" print(id(string))

__Output:__

140727154110000

The ord() function returns the number representing the Unicode code of a specified character.

x = ord("h") print(x)

__Output:__

104

x = ord("H") print(x)

__Output:__

72

The len() function returns the count of items present in a specified object.

When the object is a string, then the len() function returns the number of characters present in that string.

fruit_list = ["apple", "banana", "cherry", "mango", "pear"] print(len(fruit_list))

__Output:__

5

string = "Analytics Vidhya is the Largest Data Science Community" print(len(string))

__Output:__

54

The sum() function returns a number, the sum of all items in an iterable.

If you are a beginner, I think that you don’t have a good understanding of what Iterables and Iterators are. To learn these concepts, you can refer to the **link**.

a = (1, 2, 3, 4, 5) print(sum(a, 7))

__Output:__

22

list = [1, 2, 3, 4, 5] print(sum(list))

__Output:__

15

The help() function is used to display the documentation of modules, functions, classes, keywords, etc.

If we don’t give an argument to the help function, then the interactive help utility starts up on the console.

help(print)

__Output:__

help(sum)

__Output:__

A. In-built Python functions are pre-defined functions available for use without importing any external libraries or modules. These functions provide basic functionality and operations used in programming.

A. An example of a built-in function in Python is the print() function, which displays output on the console.

A. Python has several built-in functions that provide functionality in different areas, such as data type conversion, mathematical operations, string manipulation, file operations, and more. Some examples of built-in functions in Python are len(), str(), int(), float(), range(), max(), min(), sum(), open(), sorted(), and type().

Lorem ipsum dolor sit amet, consectetur adipiscing elit,