zoukankan      html  css  js  c++  java
  • day21-双下eq方法

    class Goods:
        def __init__(self,name):
            self.name = name
        def __eq__(self,other):  #self = apple1, other = apple2
            if self.name == other.name:
                return True
            else:
                return False
    apple1 = Goods('apple')
    apple2 = Goods('apple')
    print(apple1 == apple2) #True, 双等号==触发双下__eq__方法
  • 相关阅读:
    01
    商城管理系统
    10
    09
    08
    07(3)
    07(2)
    07
    06
    jsp第一次作业
  • 原文地址:https://www.cnblogs.com/python-daxiong/p/11304119.html
Copyright © 2011-2022 走看看