avatar Bite 167. Complete a User class: properties and representation dunder methods

In this Bite you are presented with another class, User this time.

Like last Bite you are asked to complete it, see the TODOs in the code below:

  1. Complete the get_full_name property (more on properties here) that prints first and last name separated by a space.
  2. Complete the username property following its docstring.
  3. Complete the special representation dunder methods: __str__ and __repr__. Look at the tests what they should return. Brace yourself for some bonus learning for a twist we added in __repr__ (but as it's a Beginner Bite we give you a hint!)

Apart from Ned's awesome answer on SO, to give you an idea about the difference between __str__ and __repr__, check out how datetime implements them:

>>> from datetime import datetime
>>> dt = datetime.now()
>>> str(dt)
'2019-02-04 23:05:27.376407'
>>> repr(dt)
'datetime.datetime(2019, 2, 4, 23, 5, 27, 376407)'

Good luck and keep calm and code in Python!

Login and get coding
go back Beginner level
Bitecoin 2X

531 out of 544 users completed this Bite.
Will you be the 532nd person to crack this Bite?
Resolution time: ~45 min. (avg. submissions of 5-240 min.)
Our community rates this Bite 3.87 on a 1-10 difficulty scale.
» You can do it! 😌

Focus on this Bite hiding sidebars, turn on Focus Mode.

Ask for Help