python - x has type function but calling x gives a type error Python3 -


i have following python statement

x = lambda :8() 

checking type of x returns following

<class 'function'> 

but doing this

x() typeerror: 'int' object not callable 

i can solve putting parenthesis around lambda so

x = (lambda :8)() 

but wondering going on.

the problem not lie calling x, trying call 8 8(). calling integer raises error because instances of int not callable.

i can solve putting parenthesis around lambda so

what doing x = (lambda :8)() construct anonymous function returns number 8, call it, , assign name x return value.

>>> x = (lambda :8)() >>> x 8 

however, x() still raise error because again it's trying call integer.

>>> x() traceback (most recent call last):   file "<stdin>", line 1, in <module> typeerror: 'int' object not callable 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -