Home>
Things I want to do

If i display with print, it will be displayed as an object as shown below
I want to display it in words that humans can understand.
<<main.Person object at 0x7fca59411d30> ;,<main.Person object at 0x7fca59411dd8> ;,<main.Person object at 0x7fca59411e10> ;,<main.Person object at 0x7fca59411e48>]

  • Answer # 1

    Please implement__ str __ ()method in Person class.

  • Answer # 2

    Implement__ repr __and__ str __in thePersonclass.

    How to print a class or objects of class using print ()?

  • Answer # 3

    Please define the__ repr __method of the class appropriately.

    class Number:
        def __init __ (self, num):
            self.num = num
        def __repr __ (self):
            return f'number is {self.num} '
    lst = [
        Number (i) for i in range (10)
    ]
    print (lst)

    ResultsWandbox

    [number is 0, number is 1, number is 2, number is 3, number is 4, number is 5, number is 6, number is 7, number is 8, number is 9]

  • Answer # 4

    Turn up the words in the question title,
    python print class object display
    I did a google search on.

    6 ways to stringify objects in Python
    https://qiita.com/amedama/items/a53f1130f6afbb180038