Scientific notations in Python

In this tutorial, we will learn about scientific notations in Python.

Before proceeding to the scientific notations in Python, let us understand the scientific notations in detail.

Scientific notation can be defined as a method by which one expresses the numbers that are very big or small. It simplifies the arithmetic operations that are complex. It indicates these types of numbers in the decimal form for convenience.

Python uses specific syntax while using scientific notations for writing numbers that are complex. It uses E or e to make use of exponent. Complex numbers are the ones that one cannot represent in a number line.

Numbers are represented in the form of scientific notations using the format(). It can be illustrated as follows:

scientificnotationvariable1 = "{:e}".format(98700000)
scientificnotationvariable2 = "{:.2e}".format(98700000)



In the first example, the variable just formates the number in the form of scientific notation. Then, it prints the output on the terminal. In the second example, the formatting is specified up to two decimal digits while conversion to the scientific notation.

Program to show various ways to format a number in scientific notation:

print(format(7654.12345, "11.7E"))
print(format(6589.52291, "2.6e"))
print(format(0000000.987654, ".5E"))
print(format(7654.12345, "20.2E"))
print(format(6589.52291, "2.2e"))
print(format(0000000.987654, ".1E"))



This program shows the way to format the numbers using different values and then displaying the results on the terminal as shown above.

Thanks for reading!

Recommended Posts:
Python Docstrings

Leave a Reply

Your email address will not be published. Required fields are marked *