Q:

Checking if attribute exists and is truthy in Python

I am new to Python. I find myself doing this quite a lot:
if 'input_url' in inputparams and inputparams['input_url']:
    # do something with inputparams['input_url']

if 'output_url' in inputparams and inputparams['output_url']:
    # do something with inputparams['output_url']

I am using this as an equivalent to checking $_GET variables in PHP:
if(isset($_GET['var']) && $_GET['var']) { do_action(); }

Is there a better way of doing this in Python?

A:

dict.get(key) returns None if the key is not found. So if inputparams is a dict, then
if 'input_url' in inputparams and inputparams['input_url']:

can be simplified to:
if inputparams.get('input_url'):

