How do you detect if the optional parameter value was set?
Experience Level: Junior
Tags: Python
Answer
The standard way is to use a default value that the user would not be expected to pass, frequently the value None is used.
Example:
def do_something(name: str=None):
if name is None:
print("Name value not provided.")
Related Python job interview questions
What is a decorator in Python?
Python JuniorWhy would you return self from a class method?
Python JuniorHow do you define an optional parameter with no value in Python?
Python JuniorHow do you define an optional parameter with a default value in Python?
Python JuniorWhat is a data type timedelta good for in Python?
Python Junior
Chat
Oh, the operator is not available. Leave us your comments. We will answer all your questions as soon as possible.
Anonymous
Καλησπέρα.
Καλησπέρα.
Anonymous
the infinteis -3/15 so 1triition / infinet
the infinteis -3/15 so 1triition / infinet
Anonymous
e
e
Anonymous
<a href="https://inspirum.pl "
<a href="https://inspirum.pl "
Anonymous
[url]https://inspirum.pl[/url]
[url]https://inspirum.pl[/url]
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e