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:

  1. this still not function (why take a , return 5 + 3).
  2. it shows infinite recursion.

update

as per ops request.

def add_three(number):     return number + 3 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -