We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Without width=width, the code would not run (as format would have no idea what {width} should be set to.
If you're asking what it does, then it tells the format function to set all {width} parts parameter to the width variable defined at line 2.
If you're asking why {width} is there, then it tells format to space out the output of each number to the largest number string (which is found out by line 2 of the code).
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
String Formatting
You are viewing a single comment's thread. Return to all comments →
Without
width=width
, the code would not run (asformat
would have no idea what{width}
should be set to.If you're asking what it does, then it tells the
format
function to set all{width}
parts parameter to thewidth
variable defined at line 2.If you're asking why
{width}
is there, then it tellsformat
to space out the output of each number to the largest number string (which is found out by line 2 of the code).