Examveda

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

C. By making the parameter lowercase

D. By using a special keyword opt

Answer: Option B

Solution (By Examveda Team)

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.

This Question Belongs to Python Program >> Functions In Python

Join The Discussion

Comments (1)

  1. Da Ksha
    Da Ksha:
    10 months ago

    i think correct answer is B

Related Questions on Functions in Python