title: How can I store the output of print function to a variable in python?
body: <p>I have written a function that prints output to the screen in python. I want the print statements as return value when the function is called.</p>
  <pre><code>    def printer:
          print(&quot;Statement 1&quot;)
          print(&quot;Statement 2&quot;)
          ....
  </code></pre>
  <p>instead of the above</p>
  <pre><code>    def printer:
          return  x
      print(printer())
  </code></pre>