Login to manage your account

Please enter a valid email address.
Forgot Password?
Please enter a valid password.
OR

Don't have an account yet? Sign up

What is the difference between __str__ and __repr__?

  1. A __str__ is for end users; __repr__ is unambiguous and aimed at developers
  2. B __repr__ is for users
  3. C They are identical
  4. D __str__ is required in every class
Answer

__str__ is for end users; __repr__ is unambiguous and aimed at developers

If __str__ is missing Python falls back to __repr__, but not the reverse. Always define __repr__ for classes you will debug.

All Python MCQs

Login to manage your account

Please enter a valid email address.
Forgot Password?
Please enter a valid password.
OR

Don't have an account yet? Sign up as