So I'm making my first program in python 3 with operators overloading, and I'm stucked over the add (+) operator.
def __add__(self, newMember):
if(isinstance(newMember, Queue)):
tempList=self.myQueue[:] # makes a copy
tempList.extend(newMember.myQueue)
return Queue(tempList)
def __str__(self):
if not self.myQueue:
string="."
else:
string=""
for x in self.myQueue:
string=string+str(x)
if(x<len(self.myQueue)):
string=string+", "
else:
string=string+"."
return string
basically I'm making a Queue class (I know there's already such one exists), then connecting two Queue objects by typing c=c1+c2. But when I print (c), it messed up the "," and the ".". Can't get what's wrong. Any help?
tempList = Queue(self.myQueue)or something like that? I don't know much about Python but if you just assignself.myQueuetotempListthen maybetempListrefers to the same object asself.myQueue...