Classes
Learn about the differences between data types in Python and how to create your own classes, objects, and interfaces.
StartKey Concepts
Review core concepts you need to learn to master this subject
Python repr
method
Python class methods
Instantiate Python Class
Python Class Variables
Python init method
Python type() function
Python class
Python dir() function
Python repr
method
Python repr
method
class Employee:
def __init__(self, name):
self.name = name
def __repr__(self):
return self.name
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 2
What you'll create
Portfolio projects that showcase your new skills
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory