Python: 练习 __str__ __repr__ __call__ __del__Python: 练习 __str__ __repr__ __call__ __del__Python: 练习 __str__ __repr__ __call__ __del__Python: 练习 __str__ __repr__ __call__ __del__
  • 首页
  • 博客
  • 文件
  • 书签
  • 分析
  • 登录
Search
Generic filters

Python: 练习 __str__ __repr__ __call__ __del__

Published by admin at 2022年4月30日
Categories
  • Practice
Tags
class ClassA(object):
    def __init__(self):
        print("init")

    def __str__(self):
        return "str ClassA Object"

    def __repr__(self):
        return "repr ClassA Object"

    def __call__(self, *args, **kwargs):
        print(args, kwargs)

    def __del__(self):
        print(f"del {self}")


obj = ClassA()
print(obj)
print("%s" % obj)
print("%r" % obj)
obj(1, 2, a1="a", b1="b1")

运行结果:
init
str ClassA Object
str ClassA Object
repr ClassA Object
(1, 2) {'a1': 'a', 'b1': 'b1'}
del str ClassA Object

发表回复 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注

Categories

  • 猫
  • Python
  • MySQL
  • Django
  • Html/CSS
  • JavaScript
  • Vue
  • RegExp
  • php
  • Practice
  • Virtualization
  • Linux
  • Windows
  • Android
  • NAS
  • Software
  • Hardware
  • Network
  • Router
  • Office
  • WordPress
  • SEO
  • English
  • Games
  • Recipes
  • living
  • Memorandum
  • Essays
  • 未分类

归档

©2015-2022 Alaica Blog support@alaica.com