In Python, the float
type represents floating-point numbers and follows the IEEE 754 standard for floating-point arithmetic. The size of a float
in Python is typically 64 bits or 8 bytes.
my_float = 3.14
In Python, you can declare a float
variable simply by assigning a value with a decimal point to it.
The size of a float
object in Python can vary depending on the Python implementation and the underlying platform. However, in most Python implementations, including CPython (the reference implementation), the size of a float
object is typically 24 bytes.
Python float size example
You can use the sys
module to check the size of a float
object in your Python environment. Here’s an example:
import sys
float_size = sys.getsizeof(float())
print(f"Size of a float object: {float_size} bytes")
Output:
Keep in mind that the reported size may vary slightly between different Python implementations and platforms.
Do comment if you have any doubts or suggestions on this Python float topic.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
Windows 10
Python 3.10.1
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.