How can I create a function that accepts both positional and keyword arguments?

77 views

How can I create a function that accepts both positional and keyword arguments?

How can I create a function that accepts both positional and keyword arguments?

solveurit24@gmail.com Changed status to publish February 13, 2025
0

Use *args for positional arguments and **kwargs for keyword arguments.

def my_function(*args, **kwargs):
    print("Args:", args)
    print("Kwargs:", kwargs)

# Example usage:
my_function(1, 2, 3, name="Alice", age=30)
# Output:
# Args: (1, 2, 3)
# Kwargs: {'name': 'Alice', 'age': 30}

solveurit24@gmail.com Changed status to publish February 13, 2025
0