Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8046939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:56:59+00:00 2026-06-05T05:56:59+00:00

I thought I had a decent understanding of how functions work and how they

  • 0

I thought I had a decent understanding of how functions work and how they can be assigned to variables. However, I was just looking over some Learn Python the Hard Way exercises I read a few months ago (most notably exercise 21) and noticed some interesting things about the interpreter’s output.

def add(a, b):
    print "ADDING %d + %d" % (a, b)
    return a + b

Outputs:

>>> add(30, 5)
ADDING 30 + 5
35

Why does this show 35? Shouldn’t you have to write “print add(30, 5)” for the return value to show up?

>>> age = add(30, 5)
ADDING 30 + 5

>>> age
35

The variable assignment looks like it calls the function and outputs the print statement and not the return value… but the variable itself shows the value 35, why doesn’t the variable assignment do the same?

I hope these questions make sense. I’m just trying to get a better idea of what’s going on behind the scenes. If anyone has any outside reading, let me know!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T05:57:02+00:00Added an answer on June 5, 2026 at 5:57 am

    This is because the interactive interpreter displays the return value of any expression you type.

    The function you posted has two lines. In the first line, it print()s the value to the standard output. The second returns the same value out of the function. As I stated above, this also gets written to the standard output in the interactive interpreter.

    If you were to run your script via the command line (i.e. not in the interactive interpreter:

    python myscript.py
    

    You would notice that this return value is no longer printed to the standard output.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I thought I had already a decent grasp of Git, but just now I've
I thought I had got this to work before, but I just don't see
I thought I had this figured out but it turns out I'm just deleting
I thought I had a good understanding of how quicksort works, until I watched
I thought I had this answered from a previous post, but I still can't
Note: NOT Javascript. :-) Hello, I just had a random thought, and have decided
I thought I had a reasonable understanding of the this object in JavaScript. When
So I thought I had a good basic understanding of exception-handling in Java, but
I had removed some files from my iOS project a while back and thought
i have been using what i had thought to be some fairly standard iOS

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.