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

  • Home
  • SEARCH
  • 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 6080691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:05:26+00:00 2026-05-23T11:05:26+00:00

The following is a sample piece of code from a program that I’m referring

  • 0

The following is a sample piece of code from a program that I’m referring to. I realized that I hadn’t truly this concept, so I’m asking here.

class Chef(games.Sprite):
    """
    A chef which moves left and right, dropping pizzas.
    """
    image = games.load_image("chef.bmp")

    def __init__(self, y = 0, speed = 2, odds_change = 200):
        """ Initialize the Chef object. """
        super(Chef, self).__init__(image = Chef.image,
                                   x = games.screen.width / 2,
                                   y = 55,
                                   dx = speed)

        self.odds_change = odds_change
        self.time_til_drop = 0

This is what I thought is the case:

the sixth line def __init__(self, y = 0, speed = 2, odds_change = 200) gives the object its initial values and the values enclosed in the kernel:

super(Chef, self).__init__(image = Chef.image, x = games.screen.width / 2, y = 55,dx = speed) deal with these values of the object after initialization. Making the sixth line values fairly arbitary. For example I was able to change the value of y in the sixth line constructor to any arbitary number, and the object stayed in the same y coordinate on the screen. Is my understanding of this correct?

  • 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-23T11:05:27+00:00Added an answer on May 23, 2026 at 11:05 am

    What super actually does is calls the parent class’ corresponding method. http://docs.python.org/library/functions.html#super
    So, in your case, you are calling the __init__ method of the class games.Sprite from your defined class Chef

    The reason you got the object at the same position although you changed y in the sixth line because you didn’t change the parameter y=55 which you are passing to the super function. If you will change this y to something else, your object will definitely move.

    The general practice while using super is to pass the same parameters as you get from the __init__ method. In your code, you are not passing any of the parameters of __init__ to super(Chef, self).__init__ and hence the parameters defined in __init__ are more or less meaningless. So your code should be some what like this –

    class Chef(games.Sprite):
        """
        A chef which moves left and right, dropping pizzas.
        """
        image = games.load_image("chef.bmp")
    
        def __init__(self, x = games.screen.width / 2, y = 55, speed = 2, odds_change = 200):
            """ Initialize the Chef object. """
            super(Chef, self).__init__(image = Chef.image,
                                   x = x,
                                   y = y,
                                   dx = speed)     # although this will work, you should either rename dx as speed or vice-versa
    
            self.odds_change = odds_change
            self.time_til_drop = 0
    

    Rem, you can take more parameters in the __init__ method then you pass to super(Chef, self).__init__ function.

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

Sidebar

Related Questions

The following piece of code is a reduced sample from the large project I'm
I have the following sample piece of code, public class test implements Runnable{ public
The following code sample is an implementation of the Strategy pattern copied from Wikipedia
I get this nice piece of code from http://developer.android.com/resources/samples/ActionBarCompat/index.html , which able to make
I'm writing a piece of code that has to transform from an RGB image
I have the following piece of code that checks if the returned video object
I have the following piece of snippet Class Sample { Obj_Class1 o1; Obj_Class2 o2;};
I have the following sample code in a VB.NET console application. It compiles and
I have the following sample code which doesn't seem to want to run. import
In Visual C++ i wrote the following sample in a C++ program: float f1

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.