I'm a C# developer learning python.
If I want to define a class with certain attributes, but not provide default values for the attributes, how is that done?
For example (this is my best guess of how to do it):
class Spam
eggs = None
cheese = None
Or, is this legal:
class Spam
eggs
cheese
Or something else?
You don't. You assign to the attributes later on, or set them to None
.
An attribute without a value is not an attribute. Being dynamic, it's perfectly fine to assign the attribute later on without having to declare it in the class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With