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 6241967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:51:55+00:00 2026-05-24T11:51:55+00:00

Can you please explain why ‘hello world’ isn’t returned below? What do I need

  • 0

Can you please explain why ‘hello world’ isn’t returned below? What do I need to modify for it to be expressed properly when called? Thanks.

>>> class MyClass:
...     i=12345
...     def f(self):
...         return 'hello world'
...     
>>> x=MyClass()
>>> x.i
12345
>>> x.f
<bound method MyClass.f of <__main__.MyClass instance at 0x060100F8>>
  • 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-05-24T11:51:55+00:00Added an answer on May 24, 2026 at 11:51 am

    When inside the REPL (or the Python console, or whatever) the value returned by the last statement will always be printed. If it is just a value the value will be printed:

    >>> 1
    1
    

    If it is an assignment, then nothing will be printed:

    >>> a = 1
    

    But, watch this:

    >>> a = 1
    >>> a
    1
    

    Ok, so in your code above:

    >>> x=MyClass()
    >>> x # I'm adding this :-). The number below may be different, it refers to a
          # position in memory which is occupied by the variable x
    <__main__.MyClass instance at 0x060100F8> 
    

    So, the value of x is an instance of MyClass located at a spot in memory.

    >>> x.i
    12345
    

    The value of x.i is 12345, so it will be printed as above.

    >>> x.f
    <bound method MyClass.f of <__main__.MyClass instance at 0x060100F8>>
    

    The value of f is a method of x (that’s what it means to have def in front of something, it is a method). Now, since it is a method, let’s call it by adding the () after it:

    >>> x.f()
    'hello world'
    

    The value returned by f method on the MyClass instance in the variable x is ‘hello world’! But wait! There are quotes. Let’s get rid of them by using the print function:

    >>> print(x.f()) # this may be print x.f() (note the number of parens)
                     # based on different versions of Python. 
    hello world
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone please explain below in detail, 1- What is the use of ActivityManager
Can anyone please explain the below SQL statement from Oracle DB: select decode(TRIM(to_char(SYSDATE,'Day')),'Monday','3','1') from
Can somebody please explain how android.app.ProgressDialog is properly used. Since, when I call hide()
Can someone please explain how to read the below code to find last column
Can someone please explain what is going on in the code below? I understand
Can someone please explain me what's the difference between Swing and AWT? Are there
Can someone please explain why int (0.4 * 10.0) is 4 yet int ((2.4
Can someone please explain why this program outputs 0x00000004? class AndAssignment { static void
Can someone please explain what the & does in the following: class TEST {
Can anybody please explain how this could possibly happen? I am completely aware of

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.