Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
How to Call a C function in Python
Next article icon

How to Call Multiple Functions in Python

Last Updated : 16 Dec, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

In Python, calling multiple functions is a common practice, especially when building modular, organized and maintainable code. In this article, we’ll explore various ways we can call multiple functions in Python.

The most straightforward way to call multiple functions is by executing them one after another. Python makes this process simple and intuitive each function call happens in the order it’s written.

Python
def func1():     print("Hello, World!")  def func2():     print("Goodbye, World!")  func1() func2() 

Output
Hello, World! Goodbye, World! 

Explanation:

  • In this example, we have two functions: func1() and func2().
  • We call each function one by one. When executed, Python runs each function in the order it appears.

Let's take a look at other cases of calling multiple functions:

Table of Content

  • Calling Multiple Functions from Another Function
  • Calling Functions in a Loop
  • Calling Functions with Arguments
  • Calling Functions in Parallel (Concurrency)

Calling Multiple Functions from Another Function

Sometimes, we may want to group multiple function calls together within a single function. This approach can make our code more organized and easier to manage.

Python
def func1():     print("Function One Called")  def func2():     print("Function Two Called")  def call_multiple():     func1()     func2()  call_multiple() 

Output
Function One Called Function Two Called 

Explanation:

  • The call_multiple() function calls func1() and func2().
  • When we call call_multiple(), both functions are executed in sequence, allowing us to group related functionality in one place.

Calling Functions in a Loop

When we need to call multiple functions that follow a similar pattern, it’s often more efficient to use a loop. This is particularly useful when we need to execute functions that take similar arguments or perform related tasks.

Python
def add(a, b):     return a + b   def multiply(a, b):     return a * b   functions = [add, multiply]  for func in functions:     print(func(3, 5)) 

Output
8 15 

Explanation:

  • We store add and multiply functions in a list called functions.
  • We then loop through this list and call each function with the arguments (3, 5). This approach is efficient because it lets us call each function without repeating the same code.

Calling Functions with Arguments

When functions require arguments, we can still call multiple functions in sequence or from within another function. Passing the right parameters ensures that each function behaves as expected.

Python
def func1(name):     print(f"Hello, {name}!")  def func2(name):     print(f"Goodbye, {name}!")  # Calling functions with arguments func1("Alice") func2("Bob") 

Output
Hello, Alice! Goodbye, Bob! 

Explanation:

  • Both func1() and func2() require a name argument.
  • We pass different names to each function when we call them. This demonstrates how we can use functions with parameters while calling multiple functions in sequence.

Calling Functions in Parallel (Concurrency)

In some situations, we might want to execute multiple functions concurrently, especially when dealing with tasks that are independent of each other. Python provides several tools for concurrency, such as the threading and multiprocessing modules, as well as asynchronous programming with asyncio.

Python
import threading  def func1():     print("Task One Started")      def func2():     print("Task Two Started")  thread1 = threading.Thread(target=func1) thread2 = threading.Thread(target=func2)  thread1.start() thread2.start()  thread1.join() thread2.join() 

Output
Task One Started Task Two Started 

Explanation:

  • We create two threads, thread1 and thread2, each responsible for calling func1() and func2(), respectively.
  • By calling start(), both functions begin executing concurrently. This allows us to run them at the same time, rather than sequentially.
  • The join() method ensures that the main thread waits for both threads to complete before proceeding.

Next Article
How to Call a C function in Python

S

shivangtomar257
Improve
Article Tags :
  • Python
  • python-basics
Practice Tags :
  • python

Similar Reads

  • How to call a function in Python
    Python is an object-oriented language and it uses functions to reduce the repetition of the code. In this article, we will get to know what are parts, How to Create processes, and how to call them. In Python, there is a reserved keyword "def" which we use to define a function in Python, and after "d
    5 min read
  • How to Call a C function in Python
    Have you ever came across the situation where you have to call C function using python? This article is going to help you on a very basic level and if you have not come across any situation like this, you enjoy knowing how it is possible.First, let's write one simple function using C and generate a
    2 min read
  • How to Break a Function in Python?
    In Python, breaking a function allows us to exit from loops within the function. With the help of the return statement and the break keyword, we can control the flow of the loop. Using return keywordThis statement immediately terminates a function and optionally returns a value. Once return is execu
    3 min read
  • How to Recall a Function in Python
    In Python, functions are reusable blocks of code that we can call multiple times throughout a program. Sometimes, we might need to call a function again either within itself or after it has been previously executed. In this article, we'll explore different scenarios where we can "recall" a function
    4 min read
  • Python | How to get function name ?
    One of the most prominent styles of coding is following the OOP paradigm. For this, nowadays, stress has been to write code with modularity, increase debugging, and create a more robust, reusable code. This all encouraged the use of different functions for different tasks, and hence we are bound to
    3 min read
  • How to Define and Call a Function in Python
    In Python, defining and calling functions is simple and may greatly improve the readability and reusability of our code. In this article, we will explore How we can define and call a function. Example: [GFGTABS] Python # Defining a function def fun(): print("Welcome to GFG") # calling a fu
    3 min read
  • Using User Input to Call Functions - Python
    input() function allows dynamic interaction with the program. This input can then be used to call specific functions based on the user's choice . Let’s take a simple example to call function based on user's input . Example: [GFGTABS] Python def add(x, y): return x + y # Add def sub(x, y): return x -
    2 min read
  • How to run same function on multiple threads in Python?
    In a large real-world application, the modules and functions have to go through a lot of input and output-based tasks like reading or updating databases, communication with different micro-services, and request-response with clients or peers. These tasks may take a significant amount of time to comp
    3 min read
  • Pass a List to a Function in Python
    In Python, we can pass a list to a function, allowing to access or update the list's items. This makes the function more versatile and allows us to work with the list in many ways. Passing list by Reference When we pass a list to a function by reference, it refers to the original list. If we make an
    2 min read
  • How to Install functools32 in Python
    The Functools is one such module in Python, which is used for higher-order functions i.e., functions that can act on or return other functions. In general, any callable object can be treated as a function for the purposes of this module. How to install functools32 in Python The functools32 is a back
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences