How to Use Ternary Operator in Python
<p>I have this method:</p>

<pre><code>def get_compression_settings(self, media_type=None):
        return self.transmit('GET', 'compression?mediatypeid={0}'.format(media_type))
</code></pre>

<p>Is there a way I can check if media_type == None and only append mediatypeid={0} if it is ~=None in a single line using a ternary operator?</p>

<p>I know I could do the following, but it would nicer if my method could just be a single return:</p>

<pre><code>def get_compression_settings(self, media_type=None):
        endpoint = 'compression?mediatypeid={0}'.format(media_type) if media_type is not None else 'compression'
        return self.transmit('GET', endpoint)
</code></pre>
