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

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

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

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)