Q2
How can you make a parameter optional in a Python function?
A.
By using the optional keyword
B.
By providing a default value to the parameter
AnswerC.
By making the parameter lowercase
D.
By using a special keyword opt
Answer: Option B
Solution
Answer: Option B
Solution:
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.