Subtract from List of python_ (length shorter after judging)

Source: Internet
Author: User

#定义一个方法, 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.