joeyajames / Python

Python code for YouTube videos.
MIT License
1.63k stars 1.35k forks source link

instantiation #93

Open AlinDavid opened 3 years ago

AlinDavid commented 3 years ago

I'n not an expert but i would like to know if there wasn't better to type the init method like this:

class Shape: def init(self, color=None): if color == None: self.color = "" else: self.color = color

since the input for color is expected to be a string type

joeyajames commented 3 years ago

Isn't this simpler, and does the same thing? class Shape: def init(self, color=''): self.color = color

AlinDavid commented 3 years ago

It is simpler but instantiating objects like that will maybe became troublesome because every instance will receive the same reference to the "" string.