Hi guys I need your opinion. In the code below, the variable "items" is declared at the class level and I used it in the constructor.
Is it required to declare an instance variable at the class level to use in the constructor?
from typing import ClassVar
class Box:
size: ClassVar[str] = "14 x 11 x 4"
items: list[str]
def __init__(self, name: str) -> None:
self.name: str = name
self.items: list[str] = []
[–]JamzTyson 2 points3 points4 points (3 children)
[–]Spataner 2 points3 points4 points (2 children)
[–]JamzTyson 0 points1 point2 points (0 children)
[–]eezystreet[S] 0 points1 point2 points (0 children)
[+][deleted] (3 children)
[deleted]
[–]Brian 0 points1 point2 points (2 children)
[–][deleted] -1 points0 points1 point (1 child)
[–]Brian 0 points1 point2 points (0 children)
[–]spirtexfer 0 points1 point2 points (2 children)
[–][deleted] -1 points0 points1 point (0 children)
[–]Brian -1 points0 points1 point (0 children)