def html_tag( tag ):
def body( msg ):
print( "hi! :", msg )
def inn_body( msg1 ):
print( "hola: ", msg1 )
return inn_body
return body
h1 = html_tag( "h1" )
h1( "varshini" )
h1( "subiksha" )
/// How do i access the inn_body()?
def html_tag(tag):
def body(msg):
print("hi! :", msg)
def inn_body(msg1):
print("hola: ", msg1)
return inn_body
return body
h1 = html_tag("h1")
h1("varshini")
h1("subiksha")('inn_body')
Output:
hi! : varshini
hi! : subiksha
hola: inn_body
I was going to (ok, did) ask why would you want to do such a thing. Is it to allow writing code like that used in Yoriz' example? Looks confusing to me.
(Aug-09-2020, 03:40 PM)deanhystad Wrote: [ -> ]I was going to (ok, did) ask why would you want to do such a thing. Is it to allow writing code like that used in Yoriz' example? Looks confusing to me.
No, I was getting a hang of closures concept in python and I wanted to know on how to access a nested fuction using the closure method.