python类中方法__str__()和__repr__()简单粗暴总结

在交互式模式下,类中同时实现__str__()和__repr__()方法:python 直接输入实例名称显示repr返回的类容;web 用print打印实例名称显示str返回的内容;svg >>> class Test: ... def __repr__(self): ... return 'Test -> return repr' ... def __str__(
相关文章
相关标签/搜索