in ,

🧑🏻‍💻 TechAcademy | Active engineer explains how to specify the number of digits after the decimal point in Python [For beginners]

An active engineer explains how to specify the number of digits after the decimal point in Python [for beginners]

Explains how to specify the number of digits after the decimal point in Python.

If you're not familiar with Python in the first place, read an article that explains what Python is and get a better understanding.

 

This article is based on the contents of the TechAcademy online boot camp Python course.

 

 

How to output by specifying the number of digits

How to use format

You can specify the number of digits and output a numerical value by specifying the format starting with: in the replacement field ({}) used in format.

First, let's see the case where nothing is specified.
 

num = 123.456 print ('{}'. format (num)) # => 123.456

 
Next, try specifying the number of digits as 10 digits.

By setting the replacement field to {:10}, the output will be 10 digits.
 

num = 123.456
print ('{:10}'.format (num))
# => ...

→See more in Tech Tech Magazine