
Functions
def greet(name): # <-Function Header # Function Documentation, i.e. Docstring """This function greets the person passed in as a parameter.""" print(f"Hello, {name}!") # <-Function Bodygreet("Alice")def add_numbers(a, b): """This function adds two numbers and returns the result.""" result = a + b return resultresult = add_numbers(5, 3)def multiply(a, b): """This function multiplies two numbers and returns the result.""" result = a * b return resultdef power(base, exponent=2): """This function calculates the power of a number.""" result = base ** exponent return resultdef print_args(*args, **kwargs): """This function prints the arguments passed to it.""" print("Positional arguments:", args) print("Keyword arguments:", kwargs)
Last updated