您的位置:首页 > 编程语言 > Python开发

Python学习笔记(二十二)——小甲鱼第四十三讲

2019-01-29 17:34 267 查看

0、不会

 

1、对于a+b,如果a对象的__add__方法没有实现或者不支持相应操作,Python会自动调用b的__radd__方法

 

2、使用super()这个函数

 

3、为基类起别名,在类定义的时候,使用别名代替你要继承的基类

 

4、在类中直接定义的(没有self)变量就是静态属性

 

5、静态方法只需要在普通方法前边加上@staticmethod修饰符即可

 

 

0、

class A:

    def __init__(self,*arg):

        if not arg:

            print('并没有传入参数')

        else:

            print('传入了%d个参数' % (len(arg)))

            for each in arg:

                print(each,end='')

 

               

>>> a=A(1,2,3)

传入了3个参数

123

 

1、

class word(str):

    def __gt__(self,other):

        return len(self) > len(other)

    def __lt__(self,other):

        return len(self) < len(other)

    def __ge__(self,other):

        return len(self) >= len(other)

    def __le__(self,other):

        return len(self) <= len(other)

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: