Skip to content
Advertisement

Generate list of numbers in specific format

I need to generate a list of numbers in a specific format. The format is

JavaScript

I know how to generate a normal list of numbers using range

JavaScript

So, is there any built-in way in python to generate a list of numbers in the specified format.

Advertisement

Answer

Python string formatting allows you to specify a precision:

Precision (optional), given as a ‘.’ (dot) followed by the precision.

In this case, you can use it with a value of 2 to get what you want:

JavaScript

You could also use the zfill function:

JavaScript

or the string format function:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement