I came across code like
print "Users connected: %d" % (userCount, )
I was wondering, is there any reason of not writing them in
print "Users connected: %d" % userCount
They seem having the same output
The code without an explicid tuple may bite you if your variable contains a tuple.
>>> nums = (1, 2, 3, 4)
>>> print "debug: %r" % (nums, )
debug: (1, 2, 3, 4)
>>> print "debug: %r" % nums
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: not all arguments converted during string formatting
So always using a tuple in format string syntax is a part of defensive coding.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With