#定义一个方法, you can subtract from a list
classV (object):def __init__(self,*value): Self.value=valuedef __sub__(self,other):#Take out a longer object and remove the length of the short object to spareR=Len (self.value) s=Len (other.value)ifS>r:r,s=s,r L=[]#subtraction Results temporary storage list forIinchRange (r):#when the number of digits is long, the long-out part of the calculation is ... ifLen (self.value) >s andI>s-1: L.append (Self.value[i])#when the number of digits is long, the long-out part of the calculation method is ... elifLen (other.value) >s andI>s-1: L.append (-Other.value[i])#The way in which both the meiosis and the meiosis are processed is ... Else: L.append (Self.value[i]-Other.value[i])#converts the operation (subtraction) result to V type and returnsL=v (*l)returnL#customizing str to output in list form def __str__(self):returnSTR (self.value)#into character type,a=v (1,2,3,4,5,6) b=v (A)Print(A-B)
Subtract from List of python_ (length shorter after judging)