python類中方法__str__()和__repr__()簡單粗暴總結

在交互式模式下,類中同時實現__str__()和__repr__()方法:python 直接輸入實例名稱顯示repr返回的類容;web 用print打印實例名稱顯示str返回的內容;svg >>> class Test: ... def __repr__(self): ... return 'Test -> return repr' ... def __str__(
相關文章
相關標籤/搜索