ExamVeda
Login
Home
Functions in Python
?

How can you make a parameter optional in a Python function?

Answer & Solution
Correct Answer: Option B
In Python, you can make a parameter optional by assigning it a default value in the function definition.

When a default value is specified, the parameter becomes optional, and the function can be called without explicitly passing a value for it.

For example:


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


Here, the parameter name is optional because it has a default value of "Guest".

Note: If no value is provided when the function is called, the default value will be used.
Examveda
Question posted by Examveda
Community

Join the Discussion

1 Comment
Da Ksha
Da Ksha 2 years ago
i think correct answer is B