I have function declaration like:
def function(list_of_objects = None)
and if *list_of_objects* not passed (is None) I need to define it like empty list. The explicit way is:
def function(list_of_objects = None):
if not list_of_objects:
list_of_objects = list()
or
def function(list_of_objects = None):
list_of_objects = list() if not list_of_objects else list_of_objects
Does above code equals the next one?
def function(list_of_objects = None):
list_of_objects = list_of_objects or list()
I tested it, but I'm still not sure
>>> def func(my_list = None):
... my_list = my_list or list()
... print(type(my_list), my_list)
...
>>> func()
(<type 'list'>, [])
>>> func(['hello', 'world'])
(<type 'list'>, ['hello', 'world'])
>>> func(None)
(<type 'list'>, [])
>>>