How can I print the Truth value of a variable?
<p>In Python, variables have truthy values based on their content. For example:</p>

<pre><code>&gt;&gt;&gt; def a(x):
...     if x:
...         print (True)
... 
&gt;&gt;&gt; a('')
&gt;&gt;&gt; a(0)
&gt;&gt;&gt; a('a')
True
&gt;&gt;&gt; 
&gt;&gt;&gt; a([])
&gt;&gt;&gt; a([1])
True
&gt;&gt;&gt; a([None])
True
&gt;&gt;&gt; a([0])
True
</code></pre>

<p>I also know I can print the truthy value of a comparison without the if operator at all:</p>

<pre><code>&gt;&gt;&gt; print (1==1)
True
&gt;&gt;&gt; print (1&lt;5)
True
&gt;&gt;&gt; print (5&lt;1)
False
</code></pre>

<p>But how can I print the <code>True</code> / <code>False</code> value of a variable? Currently, I'm doing this:</p>

<pre><code>print (not not a)
</code></pre>

<p>but that looks a little inelegant. Is there a preferred way?</p>

<p>Use the builtin <code>bool</code> type.</p>

<pre><code>print(bool(a))
</code></pre>

<p>Some examples from the REPL:</p>

<pre><code>&gt;&gt;&gt; print(bool(''))
False
&gt;&gt;&gt; print(bool('a'))
True
&gt;&gt;&gt; print(bool([]))
False
</code></pre>

python python-3.x boolean output