Key Concepts

Review core concepts you need to learn to master this subject

Python repr method

class Employee: def __init__(self, name): = name def __repr__(self): return john = Employee('John') print(john) # John

The Python __repr__() method is used to tell Python what the string representation of the class should be. It can only have one parameter, self, and it should return a string.

Learn Python: Classes
Lesson 1 of 1