Calling a Function in Python

Defining a function only gives it a name, specifies the parameters that are to be included in the function and structures the blocks of code.

Once the basic structure of a function is finalized, you can execute it by calling it from another function or directly from the Python prompt. Following is the example to call printme() function ?

Example

# Function definition is here
def printme(str):
    """This prints a passed string into this function"""
    print(str)
    return

# Now you can call printme function
printme("I'm first call to user defined function!")
printme("Again second call to the same function")

When the above code is executed, it produces the following result ?

I'm first call to user defined function!
Again second call to the same function

Function Calling Syntax

The basic syntax for calling a function is function_name(arguments). The function call must match the parameters defined in the function ?

def greet(name, age):
    print(f"Hello {name}, you are {age} years old!")

# Calling the function with required arguments
greet("Alice", 25)
greet("Bob", 30)
Hello Alice, you are 25 years old!
Hello Bob, you are 30 years old!

Key Points

  • Functions must be defined before they are called
  • Function calls must provide the correct number of arguments
  • Functions can be called multiple times with different arguments
  • The return statement is optional ? if omitted, the function returns None

Conclusion

Function calling in Python is straightforward using the function_name(arguments) syntax. Ensure the function is defined before calling it and provide the correct number of arguments as specified in the function definition.

Updated on: 2026-03-25T07:36:52+05:30

580 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements