I have the following function declaration:
def set_data(obj=None, name='delp', type=None):
Is there a python shortcut, where type is equal with 'name' value(default r passed) if is None ?
The usual idiom is:
def set_data(obj=None, name='delp', type=None):
if type is None:
type = name
(But don't actually use type as a variable name, it'll mask the built in function as described here: Is it safe to use the python word "type" in my code?)
type = type or name.NoneNone but it is false, just for one example. If you want to be as concise as possible, a conditional expression (docs.python.org/3/reference/…) is one alternative.None. It could be enough. Although I admit it is not enough for many other situations.type = name if type is None else type
reserved words, for your own sake (and probably everyone else working with your code), please :)