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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:43:09+00:00 2026-05-30T03:43:09+00:00

I’ve done some reading and can’t grasp this as fully as I’d like to.

  • 0

I’ve done some reading and can’t grasp this as fully as I’d like to. I’m making a little “choose your own adventure” game from the LPTHW tutorial, here’s the full script: http://codepad.org/YWVUlHnU

What I don’t understand is the following:

class Game(object):

    def __init__(self, start):
        self.quips = [
            "You died. Please try again.",
            "You lost, better luck next time.",
            "Things didn't work out well. You'll need to start over."
            "You might need to improve your skills. Try again." 
        ]
        self.start = start

I get that we’re creating a class, but why define __init__? Later on I do stuff like print self.quis[randint(0, len(self.quips)-1)] which prints one of the four strings in quips, but why wouldn’t I just create a function called quips or something?

  • 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-30T03:43:10+00:00Added an answer on May 30, 2026 at 3:43 am

    When you call Game("central_corridor"), a new object is created and the Game.__init__() method is called with that new object as the first argument (self) and "central_corridor" as the second argument. Since you wrote a_game = Game(...), you have assigned a_game to refer to that new object.

    This graphic may make the process easier to understand:

    Python object creation

    Note: The __new__ method is provided by Python. It creates a new object of the class given as the first argument. The built-in __new__ method doesn’t do anything with the remaining arguments. If you need to, you can override the __new__ method and utilize the other arguments.

    The practical reason __init__() exists in your program is set the start attribute on the Game instance you create (the one you call a_game), so that the first call to a_game.play() starts in the location where you want it to.

    You’re right about quips. There is no reason to have quips be set up in __init__(). You can just make it a class attribute:

    class Game(object):
        quips = ["You died. Please try again.",
                "You lost, better luck next time.",
                "Things didn't work out well. You'll need to start over."
                "You might need to improve your skills. Try again." ]
        def __init__(self, start):
            self.start = start
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

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.