Meaning of the statement : {0:.3%}".format(accuracy) in[ print "Accuracy : %s" % "{0:.3%}".format(accuracy)]

#1

Please can anyone explain the meaning of the statement : “{0:.3%}”.format(accuracy) and a reference for this kind of syntax(if available).

Thanks!

#3
``````accuracy = .80944625
print "Accuracy: %s" % (accuracy)
``````

The above statement %s is a placeholder. A crude way to understand what placeholder is that it tells print to replace %s with accuracy.

``````print "Accuracy: %s" % '{:%}'.format(accuracy)
``````

The above statement tells print to replace %s with accuracy but first convert accuracy to percentage from decimal. so 0.50 become 50.000000%
Basically, we are formatting accuracy here.

``````print "Accuracy: %s" % '{0: 3%}'.format(accuracy)
``````

I’m not sure of the role of 0:3 here. It is usually used for padding. Just replace 3 with 50 and you’ll know what I’m trying to explain

Refer to both for a better explanation:

#4

Thanks!!! Understood it perfectly now!!!