How to print actual name of variable class type in function?

前端 未结 4 1879
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-29 04:21

I\'m trying to return variable name, but i keep getting this:

Below is my cod

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-29 05:21

    Python prints the location of class objects in memory if they are passed to the print() function as default. If you want a prettier output for a class you need to define the __repr__(self) function for that class which should return a string that is printed if an object is passed to print(). Then you can just return guy1

提交回复
热议问题