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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:08:08+00:00 2026-06-09T18:08:08+00:00

We have a class with some mathematical functions inside class MyObjects(object): q=1 #could be

  • 0

We have a class with some mathematical functions inside

class MyObjects(object):
    q=1      #could be any number
    def f(x,y):
        return q*y+x    #could be any mathematical function

Let’s say we want to create 100 new objects named like object_1 , object_2…object_100 of this class and all of them must have a variable q defined, but defined for each object as q_1 , q_2 … q_100 but we want every time an object is created to increment the value of q like if q=1:
q_1=q+1
q_2=q_1+1
and so on. As displayed previously all objects must use the f(x,y) function of the class named for each object like f_1 , f_2 … f_100 . the number of objects generated is going to be set by the user with input() and that is the reason i would like to automate this procedure which is very cumbersome to do “by hand” by adding that is something like a hundred objects in the code. So can i automate this procedure? Python begginer, monty python veteran lol. Feel free to edit the question if you can rephrase it in a more precise manner.

  • 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-09T18:08:10+00:00Added an answer on June 9, 2026 at 6:08 pm

    Define a class attribute q and an instance attribue q.
    And every time a new instance is created the MyObjects.q will be incremented and that incremented value will be assigned to self.q

    class MyObjects(object):
        q=0
        def __init__(self):
           MyObjects.q+=1
           self.q=MyObjects.q
    
        def f(self,x,y):
            return self.q*y+x
    inp=input("Enter number of objects: ")
    dic={}
    for x in range(1,inp+1):
        dic[x]=MyObjects()
    

    output:

    >>> dic[1].q
    1
    >>> dic[2].q
    2
    >>> dic[3].q
    3
    >>> dic[1].f(2,5)
    7
    >>> dic[2].f(2,5)
    12
    >>> dic[3].f(2,5)
    17
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I have some class objects, each with three properties. Once one class object
I have some class around this code, let call it ToolbarButton TBBUTTON tbbutton; ZeroMemory(&tbbutton,
I have some class that I'm passing as a result of a service method,
I have some class SimpleButton . It is a Child of Button class. Button
Suppose I have some class which has a property actor_ of type Actor .
I have a class with some method that depend by one parameter. What is
So I have some class starting with #include <wchar.h> #include <stdlib.h> and there is
If I have a class with some value member that I want to store
So I have a class is something like this public class Order { //some
the basic idea is that you have some class that has a reference type

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.