13.10.20 08:06, malincns@163.com пише:
PEP 515 added underscore to numeric literals, it brings better readability.
PEP 515 -- Underscores in Numeric Literals https://www.python.org/dev/peps/pep-0515/
Is it possible to add _KB, _MB, _GB to numeric literals, for example:
200_KB (200*1024) 150_MB (150*1024*1024) 2_GB (2*1024*1024*1024)
Do you think it's a good code style?
First, according to modern standard, 1 kilobyte contains 1000 bytes. 1024 bytes is 1 kibibyte. But in some applications 1 kilobyte means 1024 bytes. I do not even want to mention applications in which 1 "megabyte" is equal to 1000*1024 bytes. It all leads to confusion. Second, why use bytes units? Not every integer value measures the amount of memory. If you multiply 2 bytes by 3 bytes, do you get 6 square bytes? If you divide 60 by 5 bytes, do you get 12 reversed bytes?