K
K
K A2020-03-09 10:13:14
Python
K A, 2020-03-09 10:13:14

How, when calling a class object via print, was its attribute displayed?

How to implement to print id?

class User():
    id = 12345678

user1 = User()
print(user1)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Tikhonov, 2020-03-09
@russrage

def __str__(self):
    return str(self.id)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question