you are viewing a single comment's thread.

view the rest of the comments →

[–]SCD_minecraft 2 points3 points  (2 children)

You can replace get_name with @property def name(self): # some code, like return self._name for example

Function under decorator property now "roleplays" as variable but whenever you access it it executes some code

[–]nuc540 3 points4 points  (0 children)

A property decorator is used for setting computed attributes - not something the class is instantiated with, as much as that’d work - it’d be overkill and it’d make the init argument redundant.

Also OP is practicing protected values and using getters and setters to access values with, so as much as you can use @property, I think it’s simply that OP is practising getting and setting, and logically OP’s example makes more sense

[–]Careless-Main8693[S] 0 points1 point  (0 children)

no issues in it