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: and so on. As displayed previously all objects must use the f(x,y) function of the class named for each object like
q_1=q+1
q_2=q_1+1f_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.
Define a class attribute
qand an instance attribueq.And every time a new instance is created the
MyObjects.qwill be incremented and that incremented value will be assigned toself.qoutput: