No, they are not the same.
You can reverse the first one, then you have
data = list(data) if data is not None else []
vs.
data = list(data) if data else []
Or you can reverse the 2nd one, then you have
data = [] if not data else list(data)
vs.
data = [] if data is None else list(data)
So your question boils down to
- whether
if data is not None
is the same as if data
or alternatively
- whether
if data is None
is the same as if not data
.
These are semantically different:
if data is None
is only true if data is None
,
if not data
is true if data has any "falsey" value: e. g. None
, 0
, ""
, False
, ()
, {}
, []
etc.