Sobes.tech
Middle

Lisage funktsiooni argumentidele vaikimisi väärtused.

sobes.tech AI

Vastus AI-lt

In programming languages like Python, default values for function arguments are set directly in the function definition. This allows calling the function without specifying these arguments, and they then take the predefined values.

Python example:

def greet(name="Guest", greeting="Hello"):
    print(f"{greeting}, {name}!")

# Function calls

greet()  # Outputs: Hello, Guest!
greet("Anna")  # Outputs: Hello, Anna!
greet(greeting="Good morning")  # Outputs: Good morning, Guest!

This approach simplifies the use of functions and makes the code more readable and flexible.