Functions are defined with def keyword. They can take parameters, have default values, and return results. Python supports *args and **kwargs.
# Example: Function with default parameter
def greet(name, greeting="Hello"):
return f"{greeting}, {name}!"
print(greet("Alice"))
print(greet("Bob", "Hi"))Write a function max_of_three(a, b, c) that returns the largest of three numbers. Test with max_of_three(3, 7, 5) and print the result.
Loading Python runtime (Pyodide)...
Write a function is_palindrome(s) that returns True if s reads the same forwards and backwards (case-insensitive). Test with "Racecar" and print the result.
Loading Python runtime (Pyodide)...
Write a recursive function factorial(n) that computes n!. Print factorial(6).
Loading Python runtime (Pyodide)...