Python Built-in Functions

Python provides numerous built-in functions that allow you to perform various tasks efficiently. These functions are always available and can be used without importing any modules. Understanding these functions can help you write more efficient code.Python's built-in functions are extremely useful for performing common tasks quickly and efficiently. These functions save time and reduce the need for writing extra code. By mastering these functions, you can significantly enhance your coding skills.

What are Built-in Functions?

Built-in functions are predefined functions in Python that are ready to use. These functions help with tasks like data type conversion, mathematical operations, and many more. Below are some commonly used built-in functions with their explanations and examples.

List of Commonly Used Built-in Functions

Function Description
len() Returns the length of an object (e.g., list, string, tuple).
type() Returns the type of the object.
print() Prints the specified message to the console.
input() Allows the user to take input from the keyboard.
sum() Returns the sum of all items in an iterable.
max() Returns the largest item in an iterable.
min() Returns the smallest item in an iterable.
abs() Returns the absolute value of a number.
round() Rounds a floating-point number to the nearest integer.
sorted() Returns a sorted list of the specified iterable.

Examples

1. Using len() and type() Functions


my_list = [10, 20, 30, 40]
print("Length of list:", len(my_list))
print("Type of list:", type(my_list))
            

Output

Length of list: 4 Type of list: <class 'list'>

2. Using sum(), max(), and min() Functions


numbers = [5, 10, 15, 20]
print("Sum:", sum(numbers))
print("Maximum:", max(numbers))
print("Minimum:", min(numbers))
            

Output

Sum: 50 Maximum: 20 Minimum: 5

3. Using abs() and round() Functions


num = -7.8
print("Absolute value:", abs(num))
print("Rounded value:", round(num))
            

Output

Absolute value: 7.8 Rounded value: -8

Example 4: Using sorted() Function


unsorted_list = [3, 1, 4, 1, 5, 9]
sorted_list = sorted(unsorted_list)
print("Sorted List:", sorted_list)
            

Output

Sorted List: [1, 1, 3, 4, 5, 9]