Open In App

Python - Call function from another function

Last Updated : 22 Sep, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In Python, one function can call another function to break a problem into smaller, manageable tasks. This makes code easier to read, reuse, and maintain.

Example:

Python
def greet(name):
    return f"Hello, {name}!"

def welcome(name):
    message = greet(name)  # calling another function
    return f"{message} Welcome to Python."

print(welcome("Carlos"))

Output
Hello, Carlos! Welcome to Python.

Explanation: the function welcome() calls greet() to get a greeting for the given name. The returned greeting is then combined with additional text and printed.

How Does Function Execution Work in Python?

Python uses a stack data structure (Last-In-First-Out) to handle function calls.

  • When a function is called, the current state of the calling function is pushed into the stack.
  • Control moves to the called function.
  • Once the called function finishes execution, its result is returned and popped from the stack.
  • The program then resumes execution in the calling function.
Working of Functions when one Function calls another Function
Working of Functions when one Function calls another Function

Let’s look at some examples to understand how a function can call another function in Python:

Example 1. Simple Function Calling Another Function

In this example, we define a function double() to multiply a number by 2, and another function add_and_double() that calls double() after adding two numbers.

Python
# Function to double a number
def double(x):
    return x * 2

# Function that calls 'double'
def add_and_double(a, b):
    total = a + b
    return double(total)

# Example usage
result = add_and_double(3, 4)
print("Result:", result)

Output
Result: 14

Example 2: Calling Parent Class Function from Child Class Function

Functions can also be reused across classes by using inheritance. The child class can call methods defined in the parent class.

Python
# Parent class
class A:
    def greet(self):
        return "Hello from A"

# Child class
class B(A):
    def greet_b(self):
        # Call parent class function
        msg = super().greet()
        return msg + " and Hello from B"

# Create object of child class
obj = B()
print(obj.greet_b())

Output
Hello from A and Hello from B

Here,

  • greet() is the parent class function.
  • greet_b() is the child class function, which reuses the parent’s function using super().

Why Do We Call Functions from Other Functions?

This pattern is extremely common in programming because it helps:

  • Code reusability: A function can be written once and used multiple times in different contexts.
  • Readability: Code is easier to understand when broken into smaller tasks.
  • Debugging: Smaller functions are easier to test and debug individually.
  • Organization: Complex problems can be divided into manageable parts.

Article Tags :

Explore