Python - Constructors and Object Initialization
How can you modify this class to allow creating objects with or without a name?
class Animal:
def __init__(self, name):
self.name = nameHow can you modify this class to allow creating objects with or without a name?
class Animal:
def __init__(self, name):
self.name = namename is required. To make it optional, provide a default value.name=None allows creating objects with or without a name.def __init__(self, name=None): -> Option A15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions