1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Python: How does the return statement work?

  1. Mar 17, 2009 #1
    1. The problem statement, all variables and given/known data
    I am trying to write a program in which I have a function that uses the variable x.

    For example,
    def function(x):
    return x


    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?
  2. jcsd
  3. Mar 17, 2009 #2


    User Avatar
    Science Advisor
    Homework Helper

    Are you using python 3?
    The print statement was changed into a function so it would now be
    You can also do something like
    answer = function(4)
  4. Mar 17, 2009 #3
    No, I'm using python 2.4.3, I think I get the idea though.
  5. Mar 18, 2009 #4


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    It works for me. What was the error message?
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook