python - Confusion over return from function -
i new python development , have seen code seems complicated me. actual code
def somefunction(): return 5+3
when called function returns me answer 8
...
the code method saw on internet:
def somefunction(): return( somefunction(5+3))
when called function gave me error typeerror: somename() takes 0 positional arguments 1 given
i bit confused second method; can done this? in case use function in second method...
the second example utilizes recursion. problem in function:
def somefunction(): return somefunction(5+3)
we doing somefunction(5+3)
, means expect somefunction
takes parameter (by giving argument of 5+3
), when not. hence error given.
this can fixed giving parameter definition:
def somefunction(a): # parameter return somefunction(5+3)
though, note that:
- this still not function (why take
a
, return5 + 3
). - it shows infinite recursion.
update
as per ops request.
def add_three(number): return number + 3
Comments
Post a Comment