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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:58:24+00:00 2026-05-15T19:58:24+00:00

I am new to Python and while unit testing some methods on my object

  • 0

I am new to Python and while unit testing some methods on my object I noticed something ‘weird’.

class Ape(object):
    def __init__(self):
        print 'ooook'

    def say(self, s):
        print s

def main():
    Ape().say('eeek')

if __name__ == '__main__':
    main()

I wrote this little example to illustrate where I got confused. If you do Ape().say(‘eeek’) does this actually instantiate an Ape object and run the init method? I thought it wouldn’t but I had some weird side effects so now I am thinking it does?

  • 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-15T19:58:25+00:00Added an answer on May 15, 2026 at 7:58 pm

    Yes it does. That’s what Ape() does: it creates an new Ape object, and as part of that process the __init__ method gets run.

    In your example, you then call the say method of that object. Note that there would be no way to call say if you didn’t have an Ape object.

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

Sidebar

Related Questions

I am quite new in Python programming. While googling I found some of the
I am new to Python. While reading some code, I come across what is
I am new to python programming..can someone suggest some way to do the following:
I'm completely new to Python and while trying various random bits and pieces I've
I'm completely new to python (and it's been a while since I've coded much).
I am new to Python, and programming in general. While I think this question
I'm new to Python and I'm trying to read some values from an USB
Being relatively new to Python 2, I'm uncertain how best to organise my class
I want to delete some files with python scripts (while using Windows). I have
I'm very new to python and I am stuck trying to create module while

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.