I\'ve heard several times that print being a function (3.x) is better than it being a statement (2.x). But why?
I was a fan of it being a statement mainly because it
You can replace the built-in print by a custom one:
import os
import sys
def print(s):
sys.stderr.write('Will now print ' + str(s) + '.' + os.linesep)
sys.stdout.write(str(s) + os.linesep)
print(['A', 'list'])
# Output:
# stderr: Will now print ['A', 'list'].
# stdout: ['A', 'list']
You can use print inside a lambda or a function call etc.:
example_timeout_function(call=lambda: print('Hello world'), timeout=5)
do_things(print_function=print)