Python 学习笔记 043

作者: 夜羽萧轩 | 来源:发表于2019-08-03 13:45 被阅读3次

本节预告 运算符重载


问题:不同的数据类型python处理方式不同

print(1 + 2)  #3

print("1" + "2")  #12

通过运算符重载完成两个对象相加

class Person(object):

    def __init__(self, num):

        self.num = num

    #运算符重载

    def __add__(self, other):

        return Person(self.num + other.num)

    def __str__(self):

        return "num = " + str(self.num)

per1 = Person(1)

per2 = Person(2)

print(per1 + per2)

未完待续  2019年8月3日13:42:40


下节预告  练习之发短信和邮件  


哎呀,突然发现不到200字啊,而且好像也没存稿了,好烦啊!写点文,加点字数 ,这就是今天的更新内容,以上!

女人如花,花开如梦,每一个女人都是一朵花,缤纷妖娆,浪漫多情,在青春稚嫩的年华,盛开如诗,最后悄悄流淌在彼此的过往中……

相关文章

网友评论

    本文标题:Python 学习笔记 043

    本文链接:https://www.haomeiwen.com/subject/kjmxdctx.html