Reference library

Functions & basics

Reusable building blocks — parameters, returns, scope, and clear function design.

1 match
Functions & basics easy

Call a Function Dynamically by Name in Python

Use globals() to look up and call a function by its name as a string, with optional arguments.

globals dynamic-dispatch reflection
Python
def greet():
    return "Hello from greet!"

def add(a, b):
    return a + b

def multiply(a, b):
    return a * b

if __name__ == "__main__":
    func_name = "add"
    args = (3, 5)
    
    # Call function dynamically by name from globals
    result = globals()[func_name](*args)
    print(f"{func_name}({', '.join(ma…
13 0 Open

Browse by section

Each section groups closely related Python snippets.

Functions & basics — Python code examples

What you will find here

This page collects functions & basics snippets — short, copy-ready Python you can paste into our free online IDE and run without installing anything. Each sample includes a plain-English explanation and the full source code.

Samples vs tutorials and challenges

Samples are quick reference — one concept per page. For step-by-step teaching, use our Python tutorials. To test yourself, try quizzes or coding challenges. Clean up style with the Python formatter.