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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:17:42+00:00 2026-06-12T20:17:42+00:00

I have been reading a lot about Python OOP here and in the Python

  • 0

I have been reading a lot about Python OOP here and in the Python tutorial. But some questions bug me on class attributes.

Example:

class Par(object):
    def __init__(self, chip, fig):
        self.fruit = chip
        self.fig = fig
        self.pear =10
  1. Shouldn’t self.fruit = chip be self.chip = chip?
  2. How come fruit does not appear in the attribute list in the __init__() brackets but it is used?
  3. What is the difference between self.fruit = chip and self.chip = chip?
  4. What is the difference between declaring an attribute in the __init__() and declaring it outside __init__() e.g. self.pear =10
  • 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-12T20:17:43+00:00Added an answer on June 12, 2026 at 8:17 pm

    self will be an instance of Par. self.__dict__ is a dict which holds attributes of self. When you say

    self.fruit = chip
    

    an entry in the dict is created: self.__dict__ will include {'fruit':chip}.

    When you say

    def __init__(self, chip, fig):
    

    you are declaring that Par must be passed two values, chip and fig. (The self instance will be passed to __init__ for you.)

    So inside the __init__, the local variables (not attributes!) chip and fig are known.

    self.fruit = chip is creating an attribute fruit with value chip.


    For example,

    class Par(object):
        def __init__(self, chip, fig):
            self.fruit = chip
            self.fig = fig
            self.pear = 10
    
    # 99 is being passed in as the value of `chip`
    # 'bar' is being passed in as the value of `fig`    
    par = Par(99,'bar') 
    print(par.__dict__)
    

    yields

    {'fruit': 99, 'pear': 10, 'fig': 'bar'}
    

    Note that to access the attributes you would normally use, for example, par.fruit rather than par.__dict__['fruit']. I show par.__dict__ above only to give you a picture of what is going on behind the scenes.

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

Sidebar

Related Questions

I have been reading a lot about both PEP-333 and PEP-3333 . But I
I have been reading a lot about HTML 5 and some of the changes
I have been reading over a lot of questions, but cant seem to find
I have been reading a LOT of google posts and StackOverflow questions about how
I have been reading a lot about openFrameworks and Processing, But still can't make
I have been reading a lot about QR codes and how the code itself
I have been reading a lot about C++ casting and I am starting to
Lately I have been reading a lot of blog topics about big sites(facebook, twitter,
I have been reading a lot on design patterns lately and some of them
I have been reading a lot about how flash development/design had died, and as

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.