#๐ Can I make optional params in my functions?
19 messages ยท Page 1 of 1 (latest)
@hard vortex
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Can I make optional params in my functions?
Have you tried searching for optional parameters? This is a very common topic.
well I've looked at optional parameters. But the only thing that comes up is using a replacement when no parameter is provided. I want it to run as if there is no parameter if none is provided.
If possible
try 'prompt=None'
if prompt is passed then u get whatever is passed through it. otherwise it will be None. think of it as like a default value of the parameter
I'm not sure what you had found during your search, but it's simply:
def get_string(prompt="Some default value"):
Although that will literally print out None.
Yea i just tried it I can do it with just a blank string it seems
Yes, a empty string is a valid default value.
Should that be a fine fix or is there a better alternative?
Whether or not it's valid for your use case depends on what you expect to happen. It's perfectly acceptable though.
Alright, thank you!
!close
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.