zoukankan      html  css  js  c++  java
  • 魔术方法

    魔术方法

        __str__  : 使用print打印时调用的方法

            一个小例子

        __repr__:交互模式下调试时调用的方法

            一个小例子(注意这个例子是在ipython中完成的)

     

        __call__: 让类可以像函数一样被使用

     

    以下魔法方法为了解即可,不常用


    类名 . __bases__  查看当前类的父类

     

    类名 . __doc__  or  实例名.__doc__ 返回当前类中的说明文档(''' '''三重引号包含的内容)

     

    类名 . __dict__  以字典形式返回当前类中的所有属性

     

    实例名 . __class__()   查看当前实例化的类的原始类名


    def __add__(self,other)    实例化类1 + 实例化类2  时运行的参数

    def __sub__(self,other)    实例化类1  - 实例化类2  时运行的参数

    def __mul__(self,other)    实例化类1  实例化类2  时运行的参数

    def __mod__(self,other)   实例化类1 % 实例化类2  时运行的参数

    def __iadd__(self,other)    实例化类1 += 实例化类2  时运行的参数

    def __isub__(self,other)    实例化类1  -= 实例化类2  时运行的参数

    def __imod__(self,other)   实例化类1 %= 实例化类2  时运行的参数

    def __imul__(self,other)    实例化类1  *= 实例化类2  时运行的参数

    def __radd__(self,other)    实例化类2  + 实例化类1  时运行的参数

    def __rsub__(self,other)   实例化类2  实例化类1  时运行的参数

        一个小例子

     

  • 相关阅读:
    GB50174-2008《电子信息系统机房设计规范》
    Tickets HDU
    HDU
    [长期更新]题解合集
    网络流/费用流题目总结[持续更新]
    [转载]Maximum Flow: Augmenting Path Algorithms Comparison
    [转载]网络流笔记
    网络流各类算法简单总结与比较
    简单的算法备忘录,个人总结[长期更新]
    训练报告 18春组队04 2014西安全国邀请赛
  • 原文地址:https://www.cnblogs.com/shijin7/p/9130493.html
Copyright © 2011-2022 走看看