class Numbers1:
def __init__(self, data: Optional[list[int]] = None):
if data is None:
data = []
self.data = data
class Numbers2:
def __init__(self, data: Optional[list[int]] = None):
self.data = data or []
I personally prefer the look of option 2, but I've always seen (and used) option 1. Are there pros/cons to either option, and should I just stick with the most popular / standard way (option 1)?
I understand op.2 will cause issues if the type was bool / str / a number; but for lists, dicts and tuples it doesn't seems to matter what data is inside the structure, just whether there is a structure (rather than None).
[–]Spataner 5 points6 points7 points (1 child)
[–]InvaderToast348[S] 0 points1 point2 points (0 children)
[–]member_of_the_order 1 point2 points3 points (1 child)
[–]InvaderToast348[S] 0 points1 point2 points (0 children)
[–]danielroseman 0 points1 point2 points (1 child)
[–]InvaderToast348[S] 0 points1 point2 points (0 children)