python - Do you have to check if an array element exists (not null string) in Python3? -
if associative array exists in python3, waste check if element of exists rather using it?
should you:
if 'name' in array , not array['name'].startswith('something'):
or should just:
if not array['name'].startswith('something'):
... , python3 handle "for" you?
you can -
if not array.get('name', 'something').startswith('something'):
get()
function returns second value default if key
( name
) not found.
so in above case , return something
, if key not found in dictionary, , because of .startwith()
, not , complete conditional expression evaluate false , doing in op's first example .
Comments
Post a Comment