repr and str
1234567class User: def __init__(self, username): self.username = username instance = User("top.user.123") print(instance)
12345678910class User: def __init__(self, username): self.username = username def __repr__(self): return f"User: {self.username}" instance = User("top.user.123") print(instance)
12345678910111213class User: def __init__(self, username): self.username = username def __repr__(self): return f"User: {self.username}" def __str__(self): return f"This is a user {self.username}" instance = User("top.user.123") print(instance)
1234567891011121314class User: def __init__(self, username): self.username = username def __repr__(self): return f"User: {self.username}" def __str__(self): return f"{self.username}" instance = User("top.user.123") string = str(instance) + " is the best user!" print(string)
Everything was clear?
Thanks for your feedback!
SectionΒ 5. ChapterΒ 2
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 2.78
repr and str
Swipe to show menu
1234567class User: def __init__(self, username): self.username = username instance = User("top.user.123") print(instance)
12345678910class User: def __init__(self, username): self.username = username def __repr__(self): return f"User: {self.username}" instance = User("top.user.123") print(instance)
12345678910111213class User: def __init__(self, username): self.username = username def __repr__(self): return f"User: {self.username}" def __str__(self): return f"This is a user {self.username}" instance = User("top.user.123") print(instance)
1234567891011121314class User: def __init__(self, username): self.username = username def __repr__(self): return f"User: {self.username}" def __str__(self): return f"{self.username}" instance = User("top.user.123") string = str(instance) + " is the best user!" print(string)
Everything was clear?
Thanks for your feedback!
SectionΒ 5. ChapterΒ 2