Stack Overflow Asked by Ricardo on September 12, 2020
Is it possible to add some sort of decorator or alias to get hints on the possible inputs a variable can get in a function?
In the following example function input_var can take any values, but can I hint to use the values ‘year’,’month’ or ‘day’?
def some_function(input_var):
""" This function does something cool, use input_var as bla, blah or blahh """
if input_var=='year':
print("Selected 1")
if input_var=='month':
print("Selected 2")
if input_var=='day':
print("Selected 3")
so far I add the "hint" to the docstring, but I’m want something like this:
where it could show input_var=’year/month/day’ or something like that.
Using Jupyter notebooks, with python 3
Thanks
def foo(x: 'year/month/day'):
return "abc"
x
and press tab for suggestions it will show x : 'year/month/day'
.Correct answer by Poojan on September 12, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP