import ipywidgets as widgets
def fun():
return “1”+“2”
children = [widgets.HTML(fun())]
tab = widgets.Tab()
tab.children = children
tab.titles = [str(i) for i in range(len(children))]
tab
It’s returning only strings for a function.Even integer is considered as a string and its output is 12.
it was suppose to be 3.
In pretty much every python implementation i know of, "1" + "2" == "12"
… not sure how this is Jupyter-specific.
1 Like
import ipywidgets as widgets
def fun():
return 1
children = [widgets.HTML(fun())]
tab = widgets.Tab()
tab.children = children
tab.titles = [str(i) for i in range(len(children))]
tab
I wanted to say this code has to give the output as 1 but it’s throwing an error.
here’s the error
“TraitError: The ‘value’ trait of a HTML instance expected a unicode string, not the int 1.”
Yep. And every HTML renderer will only render strings, as an HTML file only consists of strings.
It would need to cast the output to a string, e.g.
def do_thing():
thing = 1 + 2
return f"{thing}"
1 Like