Python Built-in Functions [With Syntax and Examples]
By Rohit Sharma
Updated on Oct 28, 2025 | 11 min read | 8.07K+ views
Share:
For working professionals
For fresh graduates
More
By Rohit Sharma
Updated on Oct 28, 2025 | 11 min read | 8.07K+ views
Share:
Table of Contents
Python built-in functions are predefined functions available in Python that you can use without importing any module. They make programming faster and simpler by performing common operations like type conversion, mathematical computation, input/output handling, and more. These functions are always available, making Python more efficient and readable.
In this guide, you’ll read more about what built-in functions in Python are, their syntax and usage, the most commonly used functions with examples, user-defined vs. built-in functions, and a detailed list of all Python built-in functions with syntax and outputs.
Step into the world of data science with upGrad’s leading online Data Science Courses. No classrooms, no boundaries, just practical skills, hands-on projects, and accelerated career growth. Your journey toward a successful future in data begins today.
Popular Data Science Programs
In simple terms, built-in functions in Python are functions that are "built-in" to the Python interpreter itself. They are predefined and can be used directly in your code without the need to import any special libraries or modules.
Think of them as the essential tools in a toolbox that comes with Python. Just as you'd expect a toolbox to have a hammer, screwdriver, and wrench, you can expect Python to always have print(), len(), and int().
These functions are always available in the global namespace. This means you can call them from any part of your script, at any time, without any setup.
Key Points
Also Read: Module and Package in Python
It's important to distinguish Python built-in functions from other types of functions you'll encounter.
| Type | Description | Example |
| Built-in | Predefined in the Python core and always available. No import required. | len([1, 2, 3]) |
| User-defined | Functions you create yourself using the def keyword to perform custom tasks. | def greet(): print("Hi") |
| Library | Functions that exist inside modules (Python's "libraries") and must be imported before use. | import math; math.sqrt(16) |
Understanding what are built-in functions in Python is the first step. Next, let's see how to use them.
Also Read: Top 7 Python Data Types: Examples, Differences, and Best Practices (2025)
Every built-in function in Python follows a simple and consistent syntax:
function_name(arguments)
Some functions require arguments, while others do not.
1. No Arguments:
Some functions don't need any input.
print() # Simply prints a blank line
2. Single Positional Argument:
Most common. You provide one piece of data.
x = abs(-25)
print(x) # Output: 25
Here, -25 is a positional argument. The abs() function knows to take the first (and only) item as the number to process.
3. Multiple Positional Arguments:
The order matters.
result = pow(2, 3)
print(result) # Output: 8
pow() (power) expects the base first and the exponent second. pow(3, 2) would give 9.
4. Keyword Arguments:
Some functions let you name the arguments for clarity. This is common in more complex Python built-in functions.
rounded_num = round(5.6789, ndigits=2)
print(rounded_num) # Output: 5.68
Here, we explicitly state that the "number of digits" (ndigits) should be 2. This is clearer than just round(5.6789, 2).
Also Read: Python pow() Function Explained
A critical part of the syntax is understanding what the function gives back. This is called the return value.
Understanding this "input -> process -> output" pattern is key to using all Python built-in functions.
Data Science Courses to upskill
Explore Data Science Courses for Career Progression
There are over 60 built-in functions in Python (69 in Python 3.10). We can group them by their purpose to make them easier to learn. Below is a categorized list with syntax and detailed examples.
These Python built-in functions are used for handling numbers and converting data from one type to another. This is one of the most common tasks in programming.
| Function | Description | Example |
| abs() | Returns the absolute value of a number. | abs(-9) → 9 |
| round() | Rounds a number to the nearest integer or a specified number of decimals. | round(7.567, 2) → 7.57 |
| pow() | Returns base to the power of exponent. Can also take a third mod argument. | pow(2, 3) → 8 |
| int() | Converts a value to an integer. Can truncate floats or parse strings. | int(5.7) → 5 |
| float() | Converts a value to a floating-point number. | float(3) → 3.0 |
| complex() | Creates a complex number. | complex(2, 3) → (2+3j) |
# --- abs() ---
# Works on integers, floats, and even complex numbers (returns magnitude)
print(f"abs(-7): {abs(-7)}") # Output: 7
print(f"abs(4.5): {abs(4.5)}") # Output: 4.5
print(f"abs(complex(3, 4)): {abs(complex(3, 4))}") # Output: 5.0 (sqrt(3^2 + 4^2))
# --- round() ---
# Note: Python 3 rounds to the *nearest even* number for .5 cases
print(f"round(4.5): {round(4.5)}") # Output: 4
print(f"round(5.5): {round(5.5)}") # Output: 6
print(f"round(5.678, 2): {round(5.678, 2)}") # Output: 5.68
# --- pow() ---
# pow(base, exp) is like base ** exp
print(f"pow(3, 4): {pow(3, 4)}") # Output: 81
# pow(base, exp, mod) is (base ** exp) % mod
print(f"pow(3, 4, 5): {pow(3, 4, 5)}") # Output: 1 (81 % 5)
# --- int(), float() ---
# Essential for converting user input
user_input = "25"
age = int(user_input)
print(f"Next year, you will be: {age + 1}")
price_str = "199.99"
price_float = float(price_str)
print(f"Price with tax: {price_float * 1.18}")
These are some of the most powerful Python built-in functions. They operate on iterables—any object you can loop over, like lists, tuples, strings, sets, and dictionaries.
| Function | Description | Example |
| len() | Returns the number of items in an iterable. | len([10, 20, 30]) → 3 |
| max() | Returns the largest item. Can use a key for complex sorting. | max([4, 7, 2]) → 7 |
| min() | Returns the smallest item. Can use a key for complex sorting. | min([4, 7, 2]) → 2 |
| sum() | Returns the sum of all items in an iterable (must be numbers). | sum([1, 2, 3]) → 6 |
| sorted() | Returns a new sorted list from an iterable. | sorted([3, 1, 2]) → [1, 2, 3] |
| any() | Returns True if any element in the iterable is true. | any([False, True]) → True |
| all() | Returns True if all elements in the iterable are true. | all([True, True]) → True |
| zip() | Combines multiple iterables element-wise into tuples. | zip([1,2],['a','b']) |
| map() | Applies a function to all items in an iterable. | map(str, [1,2,3]) |
| filter() | Filters items from an iterable, keeping only those where a function returns True. | filter(lambda x: x>5, [1,7,3]) |
map(), filter(), and zip() return iterators. You often need to wrap them in list() to see the results.
# --- len(), max(), min(), sum() ---
numbers = [23, 4, 56, 1, 9]
print(f"Length: {len(numbers)}") # Output: 5
print(f"Max: {max(numbers)}") # Output: 56
print(f"Min: {min(numbers)}") # Output: 1
print(f"Sum: {sum(numbers)}") # Output: 93
# --- sorted() ---
# Does NOT change the original list
unsorted_list = [5, 1, 4]
new_sorted_list = sorted(unsorted_list)
print(f"Original: {unsorted_list}") # Output: [5, 1, 4]
print(f"New List: {new_sorted_list}") # Output: [1, 4, 5]
# Using 'key' and 'reverse'
words = ["apple", "Banana", "cherry"]
print(f"Sorted (reverse): {sorted(words, reverse=True)}")
# Sort by length
print(f"Sorted by length: {sorted(words, key=len)}")
# --- map() ---
# Applies a function to every item
nums = [1, 2, 3, 4]
# We use list() to convert the map iterator into a list
squared_nums = list(map(lambda x: x**2, nums))
print(f"Squared: {squared_nums}") # Output: [1, 4, 9, 16]
# --- filter() ---
# Keeps only items that pass a test
even_nums = list(filter(lambda x: x % 2 == 0, nums))
print(f"Evens: {even_nums}") # Output: [2, 4]
# --- zip() ---
# Combines two lists
names = ["Alice", "Bob", "Charlie"]
ages = [30, 25, 40]
combined = list(zip(names, ages))
print(f"Zipped: {combined}")
# Output: [('Alice', 30), ('Bob', 25), ('Charlie', 40)]
Also Read: How to Find Square Root in Python: Techniques Explained
These Python built-in functions help you inspect and manipulate objects, check their types, and interact with their attributes. They are essential for object-oriented and dynamic programming.
| Function | Description | Example |
| isinstance() | Checks if an object is an instance of a specified class or type. | isinstance(5, int) → True |
| type() | Returns the type of an object. | type("Hello") → <class 'str'> |
| hasattr() | Checks if an object has a given attribute (variable or method). | hasattr([], 'append') → True |
| getattr() | Gets the value of an attribute from an object. | getattr(str, 'upper') |
| setattr() | Sets the value of an attribute on an object. | setattr(obj, 'x', 5) |
| dir() | Returns a list of valid attributes and methods for an object. | dir(str) |
| id() | Returns the unique memory address (identity) of an object. | id(a) |
isinstance() is generally preferred over type() because isinstance() correctly handles inheritance, while type() does not.
# --- isinstance() vs type() ---
my_num = 5
print(f"type(my_num) == int: {type(my_num) == int}") # Output: True
print(f"isinstance(my_num, int): {isinstance(my_num, int)}") # Output: True
# In inheritance, type() fails
class MyInt(int): pass
my_new_num = MyInt(5)
print(f"type(my_new_num) == int: {type(my_new_num) == int}") # Output: False
print(f"isinstance(my_new_num, int): {isinstance(my_new_num, int)}") # Output: True (Correct!)
# --- dir() ---
# Great for debugging and exploring
print(dir("a string")) # Shows all string methods like 'upper', 'lower', 'split'
# --- hasattr(), getattr(), setattr() ---
# Used for dynamic programming
class Person:
name = "John"
p = Person()
print(f"Does p have 'name'? {hasattr(p, 'name')}") # Output: True
print(f"Get p's 'name': {getattr(p, 'name')}") # Output: John
# Set a new attribute
setattr(p, 'age', 30)
print(f"Get p's new 'age': {p.age}") # Output: 30 Subscribe to upGrad's Newsletter
Join thousands of learners who receive useful tips
These Python built-in functions manage the flow of data into and out of your program. They handle user interaction, file operations, and debugging.
| Function | Description | Example |
| print() | Displays output to the console. | print("Hello") |
| input() | Takes user input from the console (always as a string). | x = input("Enter name: ") |
| open() | Opens a file and returns a file object. | open('file.txt', 'r') |
| help() | Displays interactive help documentation for an object. | help(len) |
| eval() | (Use with caution) Executes a string as Python code and returns the result. | eval('5+7') → 12 |
| exec() | (Use with caution) Executes a block of Python statements from a string. | exec("a=5;print(a)") |
Also Read: Type Conversion & Type Casting in Python Explained with Examples
SECURITY WARNING: Never use eval() or exec() on input from a user you don't trust. It allows them to run any code on your computer, which is a massive security risk.
# --- input() ---
# Always returns a string!
name = input("What is your name? ")
age_str = input("What is your age? ")
age_int = int(age_str) # Must convert
print(f"Hello, {name}. You are {age_int} years old.")
# --- print() with 'sep' and 'end' ---
print("apple", "banana", "cherry", sep=", ")
print("This is one line...", end="")
print("...and this is the same line.")
# Output:
# apple, banana, cherry
# This is one line......and this is the same line.
# --- open() ---
# The 'with' statement is the recommended way to handle files
# It ensures the file is closed automatically
try:
with open("my_file.txt", "w") as f:
f.write("Hello, file!")
with open("my_file.txt", "r") as f:
content = f.read()
print(f"File content: {content}")
except FileNotFoundError:
print("The file was not found.")
These Python built-in functions are actually the constructors for Python's main data types. You can use them to create new objects or, more commonly, to convert between types.
| Function | Description | Example |
| dict() | Creates a dictionary. | dict(a=1, b=2) |
| list() | Creates a list (or converts an iterable to a list). | list((1,2,3)) |
| tuple() | Creates a tuple (or converts an iterable to a tuple). | tuple([4,5,6]) |
| set() | Creates a set (or converts an iterable to a set). | set([1,2,3,3]) → {1, 2, 3} |
| frozenset() | Creates an immutable (unchangeable) set. | frozenset([1,2,3]) |
| bytearray() | Creates a mutable array of bytes. | bytearray(4) |
| bytes() | Creates an immutable array of bytes. | bytes("abc", "utf-8") |
| classmethod() | Decorator to convert a method into a class method. | Used inside class |
| staticmethod() | Decorator to convert a method into a static method. | Used inside class |
# --- Creating new objects ---
my_dict = dict(name="John", age=25)
print(my_dict) # Output: {'name': 'John', 'age': 25}
# --- Converting between types ---
my_tuple = (1, 2, 3)
my_list = list(my_tuple) # Convert tuple to list
print(my_list) # Output: [1, 2, 3]
my_list_with_dupes = [1, 1, 2, 3, 3, 3]
my_set = set(my_list_with_dupes) # Remove duplicates
print(my_set) # Output: {1, 2, 3}
# --- frozenset() ---
# A set cannot be a key in a dictionary (it's mutable)
# But a frozenset can!
my_frozenset = frozenset([1, 2, 3])
my_dict_with_set_key = {my_frozenset: "value"}
print(my_dict_with_set_key)
Also Read: 4 Built-in Data Structures in Python: Dictionaries, Lists, Sets, Tuples
This final group of Python built-in functions provides a variety of useful tools for iteration, introspection, and data formatting.
| Function | Description | Example |
| enumerate() | Adds a counter (index) to an iterable. | list(enumerate(['a','b'])) → [(0, 'a'), (1, 'b')] |
| iter() | Returns an iterator object from an iterable. | iter([1,2,3]) |
| next() | Returns the next item from an iterator. | next(iterator) |
| globals() | Returns a dictionary of the current global variables. | globals() |
| locals() | Returns a dictionary of the current local variables. | locals() |
| compile() | Compiles a string source into a code or AST object. | compile('5+5','<string>','eval') |
| format() | Formats a value using a specified format. | "{} {}".format("Hi","User") |
| reversed() | Returns a reverse iterator for a sequence. | list(reversed([1,2,3])) → [3, 2, 1] |
| slice() | Creates a slice object, used for [] notation. | slice(1,5) |
| hash() | Returns the hash value of an object (for dictionary lookups). | hash('python') |
# --- enumerate() ---
# The modern way to loop with an index
fruits = ['apple', 'banana', 'cherry']
for i, fruit in enumerate(fruits, start=1):
print(f"Fruit {i}: {fruit}")
# Output:
# Fruit 1: apple
# Fruit 2: banana
# Fruit 3: cherry
# --- iter() and next() ---
# This is how 'for' loops work under the hood
my_iter = iter([1, 2, 3])
print(next(my_iter)) # Output: 1
print(next(my_iter)) # Output: 2
print(next(my_iter)) # Output: 3
# print(next(my_iter)) # Raises StopIteration error
# --- reversed() ---
# Returns an iterator, so wrap in list()
my_list = [10, 20, 30]
print(list(reversed(my_list))) # Output: [30, 20, 10]
Also Read: Python Slicing - Techniques & Examples
Let's combine some of these Python built-in functions to solve common problems.
Example 1: Using len() and sum() for Data Analysis
A common task is finding the average of a list of numbers.
grades = [88, 92, 100, 75, 83, 95]
count = len(grades)
total = sum(grades)
average = total / count
print(f"Total students: {count}")
print(f"Average grade: {round(average, 2)}")
Output:
Total students: 6
Average grade: 88.83
Also Read: Data Analysis Using Python [Everything You Need to Know]
Example 2: Using map() and filter() for Data Cleaning
Imagine you have a list of numbers as strings, and you want to get the squares of only the even numbers.
nums_str = ["1", "2", "3", "4", "5", "6"]
# 1. Convert all strings to integers
nums_int = list(map(int, nums_str))
# -> [1, 2, 3, 4, 5, 6]
# 2. Filter out the odd numbers
even_nums = list(filter(lambda x: x % 2 == 0, nums_int))
# -> [2, 4, 6]
# 3. Square the remaining even numbers
squared_evens = list(map(lambda x: x*x, even_nums))
# -> [4, 16, 36]
print(f"Squared evens: {squared_evens}")
This shows how you can chain Python built-in functions to create a data-processing pipeline.
Example 3: Using zip() to Create a Dictionary
This is the most common use case for zip(): merging two lists into key-value pairs.
names = ['Alice', 'Bob', 'Charlie']
scores = [85, 90, 98]
# zip() creates [('Alice', 85), ('Bob', 90), ('Charlie', 98)]
# dict() converts that list of tuples into a dictionary
score_report = dict(zip(names, scores))
print(score_report)
# Output: {'Alice': 85, 'Bob': 90, 'Charlie': 98}
print(f"Bob's score: {score_report['Bob']}")
This is a clean and highly readable example of built in function usage.
Also Read: Step-by-Step Guide to Learning Python for Data Science
Example 4: Using sorted() with a key
How do you sort a list of dictionaries? sorted() handles this easily with its key argument.
students = [
{'name': 'Ravi', 'grade': 80},
{'name': 'Neha', 'grade': 95},
{'name': 'Amit', 'grade': 70}
]
# Sort by name (alphabetical)
by_name = sorted(students, key=lambda s: s['name'])
print(f"Sorted by name: {by_name}")
# Sort by grade (highest first)
by_grade = sorted(students, key=lambda s: s['grade'], reverse=True)
print(f"Sorted by grade: {by_grade}")
Also Read: Understanding List Methods in Python with Examples
You should always prefer using Python built-in functions over writing your own logic for a task they can accomplish.
| Criteria | Built-in Function | Custom Function (Loop) |
| Speed | Faster (Optimized C code) | Slower (Interpreted Python) |
| Code length | Short (e.g., sum(nums)) | Long (e.g., total=0; for n in nums: total+=n) |
| Errors | Fewer chances (battle-tested) | More chances for off-by-one errors, etc. |
| Readability | High (Standard) | Variable (Depends on programmer) |
Python built-in functions are general-purpose tools. They are not a magic solution for every problem.
Python built-in functions simplify coding by providing ready-to-use operations for data handling, computation, and input/output. They save time, reduce errors, and make code more readable. You can combine them with custom functions to build powerful programs efficiently. Mastering these functions helps you write cleaner, faster, and more effective Python code. Keep exploring their syntax and examples to strengthen your programming foundation and enhance your overall Python development skills.
Python built in functions are predefined functions that perform common tasks like calculations, input/output, and type conversions. They come bundled with the Python interpreter and can be used directly without importing modules, saving time and improving code readability.
Python built in functions are stored in the interpreter. When you call them, Python executes predefined code and returns results. For instance, len() calculates length, while print() outputs data. Each function follows a fixed syntax and performs a specific purpose.
They make programming faster and cleaner by handling frequent operations automatically. Instead of writing custom logic, you can use functions like sum() or type() to simplify development, reduce errors, and maintain consistency across Python applications.
Python offers over 70 built in functions. These include mathematical, logical, and utility functions for handling numbers, data structures, and conversions. The count may vary slightly depending on the Python version you are using.
Yes. The len() function is a popular example of built in function. It returns the total number of elements in an iterable, such as a list, string, or tuple. Example: len("Python") returns 6.
All Python built in functions follow the same format:
function_name(arguments)
Arguments are optional and depend on the function. Example: abs(-10) returns 10, while print("Hello") displays text output.
Built in functions are provided by Python itself, while user-defined functions are created manually using the def keyword. Built-in ones handle common operations, while custom ones solve specific problems as per project needs.
Popular ones include print(), len(), type(), sum(), range(), and abs(). These handle frequent tasks like displaying output, checking data types, and performing numeric or sequence-based operations efficiently.
Yes. Some built in functions like max(), min(), or print() accept multiple arguments. For example, max(4, 7, 9) returns 9. The number of arguments depends on the function’s design and purpose.
You cannot modify them directly because they are part of Python’s core. You can override them by creating a function with the same name, but this is not recommended as it may lead to unexpected behavior.
You can use dir(__builtins__) in the Python shell to view all available functions. This command lists every predefined function and constant accessible in the current Python environment.
Yes. Most Python built in functions have built-in error handling. They raise exceptions such as TypeError, ValueError, or NameError when given invalid inputs, allowing developers to debug issues easily.
These include abs(), pow(), min(), max(), and round(). They perform basic arithmetic and rounding operations without importing the math module, making number manipulation faster.
Type conversion functions convert one data type into another. Examples include int(), float(), str(), list(), and tuple(). These functions ensure compatibility between variables and data types during computation.
input() takes user input as a string, while print() displays data on the console. These two built in functions are essential for basic communication between a program and the user.
Yes. Functions like len(), sum(), and range() are often used inside loops. They help automate repetitive operations, improving code efficiency and reducing manual computations in iterative tasks.
Yes. Python is case-sensitive, meaning you must type function names exactly as defined. For instance, print() works, but Print() or PRINT() will raise a NameError.
Most do. Functions like len() or sum() return computed results, while others like print() perform actions and return None. The return type depends on the specific function used.
Yes. Built in functions work alongside imported modules. For example, you can use len() to check list size in a math or pandas context, improving integration and flexibility in larger projects.
You can learn more from the official Python documentation or trusted learning platforms like upGrad. These sources explain Python built in functions with syntax, examples, and practice exercises.
840 articles published
Rohit Sharma is the Head of Revenue & Programs (International), with over 8 years of experience in business analytics, EdTech, and program management. He holds an M.Tech from IIT Delhi and specializes...
Speak with Data Science Expert
By submitting, I accept the T&C and
Privacy Policy
Start Your Career in Data Science Today
Top Resources