Dec-28-2023, 09:43 PM
(This post was last modified: Dec-28-2023, 09:43 PM by deanhystad.)
__init_() uses the setter because the setter ensures that usernames are all lowercase. You could write the code like this:
Next time really think things through before you post. I think you are so focused on the Python that you are not thinking about the design. Logically it is obvious that you would want the same rules to apply to username if it is the initial value (set in __init__()) or if it is changed at a later time (using property).
def __init__(self,username): self._username=username.lower()But now you have two places in the code that process usernames. If you changed your code to make usernames uppercase you would have two places in the code you need to edit. Doing things in one place is always better than repeating the code in multiple places.
Next time really think things through before you post. I think you are so focused on the Python that you are not thinking about the design. Logically it is obvious that you would want the same rules to apply to username if it is the initial value (set in __init__()) or if it is changed at a later time (using property).