Python Hints for function inputs in Jupyter

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:

jupyter screenshot

where it could show input_var=’year/month/day’ or something like that.

Using Jupyter notebooks, with python 3


One Answer

  • look at function annotations.
  • Example:
def foo(x: 'year/month/day'):
  return "abc"
  • now if you type x and press tab for suggestions it will show x : 'year/month/day'.

Correct answer by Poojan on September 12, 2020

Add your own answers!

Related Questions

Undefined reference to vtable

19  Asked on November 20, 2021 by ryang


Using wildcards in between a C# DataTable Select statement

3  Asked on November 20, 2021 by bugaboo


SendKeys.send is sending more than one character

1  Asked on November 20, 2021 by onur-klekci


pwsh -Command is removing quotation marks

3  Asked on November 20, 2021 by chris-g


Django when is concrete inheritance appropriate

1  Asked on November 20, 2021 by natehawkboss


Get the sum of numbers from array objects

6  Asked on November 20, 2021 by askmen


Function to keep listening a service Angular 8

2  Asked on November 20, 2021 by rob-none


How to perform mathematical operation which is stored as character in R?

1  Asked on November 20, 2021 by hidden-layer


Ask a Question

Get help from others!

© 2022 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir