Why is 10**5 equal to 1e5 but 10**50 is not equal to 1e50 in Python?
Python 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 10**5 == 1e5
True
>>> 10**50 == 1e50
False
It's true up to 10**22. Then it's false:
>>> 10**22 == 1e22
True
>>> 10**23 == 1e23
False
Integer can be converted to scientific notation with the help of {:e} flag with the help of the format method of string. {:e} converts a number both integer or float to scientific notations.
Scientific notation, also called power-of-10 notation, is a method of writing extremely large and small numbers.
To raise a number to a power in Python, use the Python exponent ** operator. Python exponent is also related to another similar topic. The Python exponent notation is a way to express big or small numbers with loads of zeros. You can use the exponent notation e or E to replace the powers of ten.
Python 3 supports big integers and uses them whenever it can. 10**50
is a calculation on integers and produces the exact number ten to the fiftieth power. On the other hand, scientific notation always uses floating point, so 1e50
is a floating-point value that's approximately equal to ten to the fiftieth power.
>>> type(10 ** 50)
<class 'int'>
>>> type(1e50)
<class 'float'>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With