Insert Carriage Return for python text string on Windows

You can round and specify the number of digits within the format statement - I like this feature very much. To do so, instead of just having a blank {}, you can put in formatting codes.

For example to limit the output to a specified number of places past the decimal (and round) it might look like this:

x=2.03567
print "{:.0f}".format(x)
print "{:.1f}".format(x)
print "{:.2f}".format(x)
print "{:.3f}".format(x)
print "{:.4f}".format(x)

>>> 2 2.0 2.04 2.036 2.0357
Have a look at the Python online docs on string formatting with the format statement - there are a lot of possibilities…

–Mitch

1 Like