Python

P
PythonHub
Progress 0%

Python

  • Home
  • History of Python
  • Applications of Python
  • Introduction To Python
    • What is Python
    • Character Set
    • Tokens in Python
    • Python Execution Mode
    • Variable And Identifiers
    • Data Types in Python
    • Operators And Expressions
    • Constants in Python
    • Assignment Statement
    • Input / Output in Python
    • Simple Python Scripts
    • Namespace in Python
    • ๐Ÿ“ Assignments
  • Operators in Python
    • Arithmetic Operators
    • Assignment Operators
    • Shorthand Assignment Operators
    • Relational Operators
    • Logical Operators
    • Bitwise Operators
    • Special Operators
    • ๐Ÿ“ Assignments
  • Input Output in Python
    • Accept Input
    • Output Formatting
    • ๐Ÿ“ Assignments
  • Conditional Statement
    • Decision Making
    • if Statement
    • IF-ELSE STATEMENT
    • IF-ELSE LADDER
    • NESTED IF-ELSE
    • Short Hand IF-ELSE
    • ๐Ÿ“ Assignments
  • Loops
    • Introduction to Loops
    • While Loop
    • Nested While Loop
    • ๐Ÿ“ While Loop Assignments
    • For Loop
    • For Loop Examples
    • Nested For Loop
    • Nested For Loop Examples
    • Infinite While Loops
    • Infinite For Loops
    • Break, Continue and Else in Loops
    • Difference Between For and While Loop
    • For Each Loop
    • ๐Ÿ“ For Each Assignments
    • ๐Ÿ“ All Loops Assignments
  • List
    • List in Python
    • Access List Elements
    • List Functions
    • Iterate (Loop) List
    • List Comprehension
    • ๐Ÿ“ Assignments
  • Tuple
    • Tuple in Python
    • Access Tuple Elements
    • Tuple Functions
    • Iterate (Loop) Tuple
    • Unpack Tuple
    • Tuple Comprehension
    • ๐Ÿ“ Assignments
  • Set
    • Set in Python
    • Access Set Elements
    • Set Methods
    • Iterate (Loop) Set
    • Pack/Unpack Set
    • Set Comprehension
    • ๐Ÿ“ Assignments
  • Dictionary
    • Dictionary
    • Access Dictionary Items
    • Dictionary Methods
    • Iterate (Loop) Dictionary
    • Formatting Dictionaries
    • Nested Dictionaries
    • Dictionary Comprehension
    • ๐Ÿ“ Assignments
  • Diff List Tuple Set Dictionary
    • List vs Tuple
    • List vs Set
    • List vs Dictionary
    • Tuple vs Set
    • Tuple vs Dictionary
    • Dictionary vs Set
    • ๐Ÿ“ Assignments
  • Exception
    • Error vs Exception
    • Types of Exception
    • Exception Handling
    • User Defined Exception
    • Logging Exception
    • ๐Ÿ“ Assignments
  • Functions
    • Introduction to Functions
    • Modular Programming
    • Types of Functions
    • Inbuilt Functions
    • Need For User-Defined Function
    • Elements of User Defined Function
    • Function Arguments
    • Nesting of Functions
    • Recursion
    • Global Local and Non Local
    • Python Lambda Functions
    • ๐Ÿ“ Assignments
  • Python Module
    • Introduction to Module
    • Inbuilt Modules in Python
    • User Defined Module
    • ๐Ÿ“ Assignments
  • File Handling
    • Introduction to Files
    • Create File
    • Read Files
    • Write to File
    • Rename File
    • Copy File
    • Move File
    • List Files in Directory
    • Binary Files
    • Zipping and Unzipping Files
    • ๐Ÿ“ Assignments
  • Strings
    • Basics of Strings
    • String Special Operators
    • String Formatting Operators
    • String Methods
    • ๐Ÿ“ Assignments
  • Regular Expressions
  • Python OOPS
    • Basics of Object Oriented
    • What are Classes and Objects?
    • Creating Class and Object
    • OOP vs Procedural Programming
    • Difference Between Classes and Objects
    • Constructors
    • Destructor
    • Built Class Methods and Attributes
    • Class and Instance Variables
    • Inheritance in Python
    • Single Inheritance
    • Multiple Inheritance
    • Multilevel Inheritance
    • Hierarchical Inheritance
    • Hybrid Inheritance
    • Abstraction
    • Method Overriding
    • Abstract Method
    • Interfaces in Python
    • Abstract Class vs Interface
    • Public, Private and Protected
    • Overloading vs Overriding
    • Inheritance vs Composition
    • Encapsulation
    • Polymorphism
    • Inner Classes
    • ๐Ÿ“ Assignments
  • Advanced Python
    • Iterator in Python
    • Generator in Python
    • Decorator in Python
    • Type Hints in Python
    • Async/Await Programming
    • Dataclasses in Python
    • Context Managers in Python
    • Property Decorator in Python
    • __slots__ in Python
    • Enums in Python
    • Walrus Operator in Python
    • Match-Case in Python
    • ๐Ÿ“ Assignments
  • Python Standard Library
    • Collections Module
    • Itertools Module
    • Functools Module
    • Datetime Module
    • JSON Module
    • OS Module
    • Sys Module
    • Random Module
    • Math Module
    • ๐Ÿ“ Assignments
  • Python Testing
    • Unit Testing in Python
    • Pytest Framework
    • Mocking in Python
    • ๐Ÿ“ Assignments
  • Python Best Practices
    • PEP 8 Style Guide
    • Docstrings in Python
    • Logging in Python
    • Code Optimization Tips
    • Debugging Techniques
    • ๐Ÿ“ Assignments
  • MySQL Database in Python
    • Introduction to MySQL with Python
    • DBMS vs File System
    • Connecting to MySQL Database
    • Create Database in MySQL
    • Create Table in MySQL
    • Insert Data in MySQL
    • Insert Multiple Rows
    • Select Data from MySQL
    • WHERE Clause in MySQL
    • Update Data in MySQL
    • Delete Data from MySQL
    • Parameterized Queries
    • Transaction Management
    • Error Handling
    • Connection Pooling
    • MySQL Drivers Guide
    • Joins in MySQL
    • Aggregation Functions
    • Backup MySQL Database
    • Best Practices
    • ๐Ÿ“ Assignments
  • MySQL Database Operations
    • SELECT Statement
    • MySQL Operators
    • DDL Statements
    • DML Statements
    • Subqueries
    • JOIN Operations
    • Aggregation
    • Case Study
    • ๐Ÿ“ Assignments
  • Graphics in Python
  • Threads in Python
    • Introduction to Threads
    • Process vs Threads
    • Concurrent Programming & GIL
    • Uses of Threads
    • Creating Threads
    • Single Tasking
    • Multi Tasking
    • Thread Synchronization
    • ๐Ÿ“ Assignments
  • Interview Questions & Answers
  • Python Case Studies
  • Multiple Choice Questions
  • ๐Ÿ“ Practice Problems
Get in Touch
  • tech2dsm@gmail.com

© Sankalan Data Tech

Python Language Interactive Tutorial

Python: Inbuilt Functions

Python Inbuilt Functions - Complete Guide

Master Python's built-in functions โ€” ready-to-use tools for everyday programming.

Created by Sankalan Data Tech Team Verified
Data Engineers, Analysts, Scientists & Trainers
Created by experienced Python developers, data engineers, and data scientists to make programming easy through practical examples, real-world experience, and clear explanations.
On this page:
  • What are Inbuilt Functions?
  • Mathematical Functions
  • Type Conversion Functions
  • Sequence & Iterable Functions
  • String Functions
  • Utility Functions
  • Functional Programming Tools
  • Try It Yourself
  • Quiz
  • FAQ
Share this tutorial:
Twitter LinkedIn Facebook WhatsApp Reddit Telegram Email Copy Link
What You'll Learn Here
  • What are inbuilt functions โ€” Python's ready-to-use tools
  • Mathematical functions โ€” abs(), max(), min(), sum(), round()
  • Type conversion โ€” int(), str(), list(), tuple(), dict()
  • Sequence functions โ€” len(), sorted(), reversed(), enumerate()
  • Utility functions โ€” print(), input(), type(), isinstance()
  • Functional tools โ€” map(), filter(), zip(), all(), any()

What are Inbuilt Functions?

Python comes with a rich set of built-in functions that are always available without importing any modules. These functions provide essential functionality for everyday programming tasks.

๐Ÿ’ก Key concept: Python has over 70 built-in functions covering mathematical operations, type conversions, sequence manipulation, input/output, and more. They are optimized and ready to use.

Mathematical Functions

1

Math and Number Functions

# 1. abs() โ€” absolute value
print(abs(-10))    # 10
print(abs(-3.14))  # 3.14
print(abs(5))      # 5

# 2. max() โ€” maximum value
print(max(3, 7, 2, 9, 1))          # 9
print(max([10, 20, 30, 40]))       # 40
print(max("hello"))                # 'o' (highest ASCII)

# 3. min() โ€” minimum value
print(min(3, 7, 2, 9, 1))          # 1
print(min([10, 20, 30, 40]))       # 10
print(min("hello"))                # 'e'

# 4. sum() โ€” sum of iterable
print(sum([1, 2, 3, 4, 5]))        # 15
print(sum((10, 20, 30)))           # 60
print(sum([1, 2, 3], 10))          # 16 (start=10)

# 5. round() โ€” round to n decimals
print(round(3.14159))              # 3
print(round(3.14159, 2))           # 3.14
print(round(2.675, 2))             # 2.67 (floating point precision)

# 6. pow() โ€” power calculation
print(pow(2, 3))                   # 8
print(pow(2, 3, 5))                # 3 (2^3 % 5)
print(pow(5, 2))                   # 25

# 7. divmod() โ€” quotient and remainder
quotient, remainder = divmod(10, 3)
print(f"10 รท 3 = {quotient} remainder {remainder}")  # 3 remainder 1

# 8. oct(), hex(), bin() โ€” number base conversion
print(bin(10))    # 0b1010
print(oct(10))    # 0o12
print(hex(10))    # 0xa

Mathematical functions summary:

  • abs() โ€” absolute value
  • max()/min() โ€” find extremes
  • sum() โ€” add all elements
  • round() โ€” round numbers
  • pow() โ€” exponentiation
  • divmod() โ€” quotient and remainder

Quick Check: What does abs(-5) return? (Answer: 5)

Type Conversion Functions

2

Converting Between Types

# 1. int() โ€” convert to integer
print(int("123"))        # 123
print(int(45.67))        # 45 (truncates)
print(int("1010", 2))    # 10 (binary to decimal)

# 2. float() โ€” convert to float
print(float("3.14"))     # 3.14
print(float(10))         # 10.0

# 3. str() โ€” convert to string
print(str(123))          # "123"
print(str(45.67))        # "45.67"
print(str([1, 2, 3]))    # "[1, 2, 3]"

# 4. list() โ€” convert to list
print(list("abc"))       # ['a', 'b', 'c']
print(list((1, 2, 3)))   # [1, 2, 3]
print(list({1, 2, 3}))   # [1, 2, 3]

# 5. tuple() โ€” convert to tuple
print(tuple("abc"))      # ('a', 'b', 'c')
print(tuple([1, 2, 3]))  # (1, 2, 3)

# 6. dict() โ€” convert to dictionary
print(dict([("a", 1), ("b", 2)]))  # {'a': 1, 'b': 2}

# 7. set() โ€” convert to set
print(set([1, 2, 2, 3, 3, 4]))  # {1, 2, 3, 4}

# 8. bool() โ€” convert to boolean
print(bool(0))          # False
print(bool(1))          # True
print(bool([]))         # False
print(bool([1, 2]))     # True
print(bool(""))         # False
print(bool("hello"))    # True

# 9. chr() and ord() โ€” character codes
print(ord('A'))          # 65
print(ord('a'))          # 97
print(chr(65))           # 'A'
print(chr(97))           # 'a'

Type conversion functions:

  • int(), float(), str() โ€” basic conversions
  • list(), tuple(), dict(), set() โ€” collection conversions
  • bool() โ€” truth value testing
  • chr(), ord() โ€” character code conversion

Quick Check: What does bool([]) return? (Answer: False)

Sequence & Iterable Functions

3

Working with Sequences

# 1. len() โ€” get length
print(len("hello"))          # 5
print(len([1, 2, 3, 4]))     # 4
print(len((1, 2, 3)))        # 3
print(len({"a": 1, "b": 2})) # 2

# 2. sorted() โ€” return sorted list
numbers = [3, 1, 4, 1, 5, 9, 2]
print(sorted(numbers))        # [1, 1, 2, 3, 4, 5, 9]
print(sorted(numbers, reverse=True))  # [9, 5, 4, 3, 2, 1, 1]

# Sort strings by length
words = ["apple", "banana", "cherry", "date"]
print(sorted(words, key=len))  # ['date', 'apple', 'banana', 'cherry']

# 3. reversed() โ€” iterate in reverse
for num in reversed([1, 2, 3, 4]):
    print(num)  # 4, 3, 2, 1

# 4. enumerate() โ€” get index and value
fruits = ["apple", "banana", "cherry"]
for index, fruit in enumerate(fruits):
    print(f"{index}: {fruit}")
# 0: apple, 1: banana, 2: cherry

# With start index
for index, fruit in enumerate(fruits, start=1):
    print(f"{index}: {fruit}")
# 1: apple, 2: banana, 3: cherry

# 5. zip() โ€” combine iterables
names = ["Alice", "Bob", "Charlie"]
ages = [25, 30, 35]
cities = ["NYC", "LA", "Chicago"]

for name, age, city in zip(names, ages, cities):
    print(f"{name} is {age} from {city}")

# Convert to list of tuples
pairs = list(zip(names, ages))
print(pairs)  # [('Alice', 25), ('Bob', 30), ('Charlie', 35)]

# 6. range() โ€” generate sequence
print(list(range(5)))         # [0, 1, 2, 3, 4]
print(list(range(2, 8)))      # [2, 3, 4, 5, 6, 7]
print(list(range(2, 10, 2)))  # [2, 4, 6, 8]

Sequence functions:

  • len() โ€” length of sequence
  • sorted() โ€” returns sorted list
  • reversed() โ€” reverse iterator
  • enumerate() โ€” index and value pairs
  • zip() โ€” combine iterables
  • range() โ€” generate number sequence

Quick Check: What does enumerate() return? (Answer: An iterator of index-value pairs)

String Functions

4

String Manipulation Functions

# Python has many built-in string methods
text = "  Hello World!  "

# 1. strip() โ€” remove whitespace
print(text.strip())           # "Hello World!"

# 2. lower() and upper() โ€” case conversion
print("Hello".lower())        # "hello"
print("Hello".upper())        # "HELLO"

# 3. replace() โ€” replace substring
print("Hello World".replace("World", "Python"))  # "Hello Python"

# 4. split() โ€” split into list
words = "apple,banana,cherry".split(",")
print(words)  # ['apple', 'banana', 'cherry']

# 5. join() โ€” join list to string
print("-".join(["a", "b", "c"]))  # "a-b-c"

# 6. startswith() / endswith() โ€” check beginning/end
print("Hello".startswith("He"))   # True
print("Hello".endswith("lo"))     # True

# 7. find() โ€” find substring index
print("Hello World".find("World"))  # 6
print("Hello World".find("Python")) # -1 (not found)

# 8. count() โ€” count occurrences
print("Hello Hello".count("Hello"))  # 2

# 9. isdigit(), isalpha(), isalnum() โ€” character checks
print("123".isdigit())    # True
print("abc".isalpha())    # True
print("abc123".isalnum()) # True
print("abc123".isalpha()) # False

# 10. format() โ€” string formatting
name = "Alice"
age = 25
print("Hello, {}! You are {} years old.".format(name, age))
print(f"Hello, {name}! You are {age} years old.")  # f-string (Python 3.6+)

String functions:

  • strip() โ€” remove whitespace
  • lower()/upper() โ€” case conversion
  • replace() โ€” replace substrings
  • split()/join() โ€” convert between string and list
  • find() โ€” locate substrings
  • isdigit(), isalpha() โ€” character type checking

Quick Check: What does "Hello".lower() return? (Answer: "hello")

Utility Functions

5

General Utility Functions

# 1. print() โ€” display output
print("Hello World!")
print("Hello", "World", sep=", ", end="!\n")
print("Hello World", end="!")

# 2. input() โ€” get user input
# name = input("Enter your name: ")
# print(f"Hello, {name}!")

# 3. type() โ€” get object type
print(type(10))          # 
print(type("hello"))     # 
print(type([1, 2, 3]))   # 

# 4. isinstance() โ€” check type
print(isinstance(10, int))      # True
print(isinstance("hello", str)) # True
print(isinstance([1, 2], list)) # True

# 5. id() โ€” object identity
a = 10
b = 10
print(id(a))  # Memory address of a
print(id(b))  # Memory address of b

# 6. dir() โ€” list object attributes
print(dir(str))   # List all string methods
print(dir(list))  # List all list methods

# 7. help() โ€” get documentation
# help(print)
# help(str)

# 8. eval() โ€” evaluate expression
x = 5
print(eval("x * 2"))  # 10
print(eval("3 + 4"))  # 7

# 9. exec() โ€” execute code
code = """
for i in range(3):
    print(i)
"""
exec(code)  # Prints 0, 1, 2

# 10. sorted() โ€” sort any iterable
print(sorted("python"))  # ['h', 'n', 'o', 'p', 't', 'y']

Utility functions:

  • print()/input() โ€” I/O operations
  • type() โ€” get object type
  • isinstance() โ€” check type relationship
  • id() โ€” object memory address
  • dir() โ€” list attributes
  • help() โ€” get documentation

Quick Check: What does type(3.14) return? (Answer: )

Functional Programming Tools

6

map(), filter(), and Other Functional Tools

# 1. map() โ€” apply function to all elements
numbers = [1, 2, 3, 4, 5]
squared = list(map(lambda x: x ** 2, numbers))
print(squared)  # [1, 4, 9, 16, 25]

# Map with multiple iterables
a = [1, 2, 3]
b = [10, 20, 30]
sums = list(map(lambda x, y: x + y, a, b))
print(sums)  # [11, 22, 33]

# 2. filter() โ€” filter elements based on condition
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
evens = list(filter(lambda x: x % 2 == 0, numbers))
print(evens)  # [2, 4, 6, 8, 10]

# Filter strings by length
words = ["cat", "dog", "elephant", "ant", "tiger"]
long_words = list(filter(lambda x: len(x) > 3, words))
print(long_words)  # ['elephant', 'tiger']

# 3. all() โ€” all elements True?
print(all([True, True, True]))    # True
print(all([True, False, True]))   # False
print(all([1, 2, 3]))             # True (non-zero is True)
print(all([0, 1, 2]))             # False (0 is False)

# 4. any() โ€” any element True?
print(any([False, False, False]))  # False
print(any([False, True, False]))   # True
print(any([0, 0, 1]))              # True

# 5. sum() with start value
print(sum([1, 2, 3], 10))  # 16

# 6. zip() with unpacking
names = ["Alice", "Bob", "Charlie"]
ages = [25, 30, 35]
for name, age in zip(names, ages):
    print(f"{name} is {age} years old")

# 7. Combining functional tools
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# Get sum of squares of even numbers
result = sum(map(lambda x: x**2, filter(lambda x: x%2==0, numbers)))
print(result)  # 220 (4+16+36+64+100)

Functional programming tools:

  • map() โ€” apply function to every element
  • filter() โ€” keep elements that satisfy condition
  • all() โ€” check if all elements are True
  • any() โ€” check if any element is True
  • zip() โ€” combine multiple iterables

Quick Check: What does all([True, True]) return? (Answer: True)

Try It Yourself

Experiment with Python's built-in functions in the editor below.

Loading Pyodide... 0%
Python Code Editor
========================================
INBUILT FUNCTIONS PRACTICE
========================================

1. MATHEMATICAL FUNCTIONS
Numbers: [-5, 10, 3, -8, 15, 0]
Max: 15
Min: -8
Sum: 15
Absolute of -5: 5
Round 3.14159 to 2 decimals: 3.14

2. TYPE CONVERSION
int('123'): 123
float('45.67'): 45.67
str(100): 100
list('abc'): ['a', 'b', 'c']
tuple([1, 2, 3]): (1, 2, 3)
bool(0): False
bool('hello'): True

3. SEQUENCE FUNCTIONS
Text: 'Python Programming'
Length: 18
Sorted: [' ', 'P', 'P', 'a', 'g', 'h', 'i', 'm', 'm', 'n', 'o', 'o', 'r', 't', 'y', 'y']
Reversed: [4, 3, 2, 1]

4. STRING METHODS
Original: ' Hello World! '
Strip: 'Hello World!'
Upper: ' HELLO WORLD! '
Lower: ' hello world! '
Replace: ' Hello Python! '

5. FUNCTIONAL TOOLS
Numbers: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Squares: [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
Evens: [2, 4, 6, 8, 10]
All even? False
Any even? True

Inbuilt functions practice complete!
๐Ÿ†

You've Got It!

You now understand Python's built-in functions โ€” mathematical, type conversion, sequence, string, utility, and functional programming tools. These are essential for everyday Python programming.

Quick Quiz

Test what you've learned:

1. What does abs(-10) return?
2. Which function converts a string to an integer?
3. What does len("Python") return?
4. What does map() do?
5. Which function returns an iterator of index-value pairs?

Frequently Asked Questions

What is the difference between built-in functions and methods? โ–ผ

Built-in functions are called directly (e.g., len(), print()) and work on various types. Methods are called on objects (e.g., "hello".upper(), list.append()) and are specific to that object type.

How many built-in functions does Python have? โ–ผ

Python has over 70 built-in functions. You can see the full list by typing dir(__builtins__) in the Python interpreter.

What is the difference between sorted() and list.sort()? โ–ผ

sorted() returns a new sorted list and works on any iterable. list.sort() sorts the list in place and returns None. sorted() is more flexible as it works on tuples, strings, etc.

What is the difference between map() and filter()? โ–ผ

map() applies a function to every element and returns the results. filter() keeps only elements that satisfy a condition. Both return iterators.

What's a common interview question about built-in functions? โ–ผ

Common questions include: "Explain the difference between map() and filter()," "What is the difference between sorted() and list.sort()?" and "What does the zip() function do?"

Can I create my own built-in functions? โ–ผ

No, built-in functions are part of Python's core. However, you can create user-defined functions that work similarly. In advanced usage, you can also extend Python with C/C++ modules that add new built-in functions.

Where to Go From Here

Now that you know Python's built-in functions, check out these related topics:

User-Defined Functions

Learn why and how to create your own functions.

Learn More โ†’

Function Arguments

Master different types of function arguments.

Learn More โ†’

Lambda Functions

Learn about anonymous functions and their use cases.

Learn More โ†’
Interview Resources
  • Python Syntax & Variables Interview Questions
  • Top SQL Interview Questions & Answers
  • SQL Joins: Displaying Data from Multiple Tables FAQ
Previous: Types of Functions Next: Need For User-Defined Function โ†’