47. Polymorphic 多態性

48. / 49. _ _ str _ _ and _ _ repr _ _ Methods

image.png

both used for creating a string

_ _ repr _ _ is used by developers

  1. string could be used to recreated the object
  2. descriptive 描述
  3. debugging
  4. called when using the repr( ) function

_ _ str _ _ is used by str ( ) and print ( ), as well as various formating functions

  1. typically used for display purpose to end user, logging, etc
  2. if _ _ str _ _ is not implemented, Pyhton will look for _ _ repr _ _ instead

if neither is implemented and since all objects inherit from Object, will use _ _ repr _ _ defined there instead

  1. Every object actually inherits from kind of a parent or grandparent object that have default inmplementation
  2. class name, memory locations…