1

When a function has print statement and return some value, For example,

def func(n):
    print('want to ignore')
    return 2*n

I want to store the return value without executing print phrase. Like,

>>> a = ???(func(5))
>>> a
10

Is it possible? If so, please help me! Thanks.

Park
  • 11
  • 1
  • Maybe a global variable by considering its drawback would help you. – Mazdak Jan 10 '18 at 11:35
  • 2
    Yes, comment out the print statement. – cs95 Jan 10 '18 at 11:35
  • On a more serious note, this is actually possible, but not easy... see the referenced question, and also [here](http://thesmithfam.org/blog/2012/10/25/temporarily-suppress-console-output-in-python/). Furthermore, if you're using IPython, the `%%capture` magic makes this easier. – cs95 Jan 10 '18 at 11:38

0 Answers0