What is the difference between `>>> some_object` and `>>> print some_object` in the Python interpreter?

前端 未结 5 1181
礼貌的吻别
礼貌的吻别 2020-12-11 19:31

In the interpreter you can just write the name of an object e.g. a list a = [1, 2, 3, u\"hellö\"] at the interpreter prompt like this:

>>&         


        
5条回答
  •  庸人自扰
    2020-12-11 19:48

    The print statement always calls x.__str__() method while (only in the interactive interpeter) simply calling a variable the objects x.__repr__() method ia called.

    >>> '\x02agh'
    '\x02agh'
    >>> print '\x02agh'
    'agh'
    

提交回复
热议问题