CS101 Classes
Learn how to create Classes in Python
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 1