當前位置:成語大全網 - 英語詞典 - python __repr__的作用

python __repr__的作用

1,嘗試生成這樣壹個字符串,將其傳給 eval可重新生成同樣的對象 。

2,否則,生成用尖括號包住的字符串,包含類型名和額外的信息。

壹,這個簡單 str是顯示給用戶用的 repr是給機器用的。

答: ?

1,class A(object)

2,print "this is A class" ? def __repr__(self): print "this is repr func" ?a = A() 比如print a 調用的是a的__str__方法 ?

3,而如果妳在python解釋器裏直接敲a後回車,調用的是a.__reprpython?str和repr的區別。