nikhil.io

one thing tagged “code

Plurals in Python

>>> n = 0 >>> print "%d item%s" % (n, "s"[n==1:]) 0 items >>> n = 1 >>> print "%d item%s" % (n, "s"[n==1:]) 1 item >>> n = 2 >>> print "%d item%s" % (n, "s"[n==1:]) 2 items # If you might want to print negative items, add abs to the test: >&g…