Junior — Middle
What is the purpose of parameters in functions and why is their use important?
sobes.tech AI
Answer from AI
Parameters in functions are used to pass input data to the function, allowing it to work with different values without changing the function's code.
Using parameters is important because:
- It makes functions universal and reusable.
- It improves code readability and structure.
- It provides flexibility, enabling the function to perform different tasks depending on the passed arguments.
Example:
def greet(name):
print(f"Hello, {name}!")
greet("Anna") # Outputs: Hello, Anna!
greet("Ivan") # Outputs: Hello, Ivan!