Python: How does the return statement work?

  • Context: Python 
  • Thread starter Thread starter jumbogala
  • Start date Start date
  • Tags Tags
    Python Work
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
3 replies · 13K views
jumbogala
Messages
414
Reaction score
4

Homework Statement


I am trying to write a program in which I have a function that uses the variable x.

For example,
def function(x):
x=x+2
return x

function(4)

Now I want to print out what x was inside the function. I thought I would just say
"print function(4)", but it's giving me an error message. "print function(x)" doesn't work either.

What am I doing wrong?
 
Physics news on Phys.org
No, I'm using python 2.4.3, I think I get the idea though.