Declaring a number in Python. Possible to emphasize thousand?

让人想犯罪 __ 提交于 2019-11-29 15:17:26

This is actually just now possible in Python 3.6.

You can use the first format that you showed:

a = 35_000

because underscores are now an accepted separator in numbers. (You could even say a = 3_5_00_0, though why would you?)

The second method you showed will actually create a tuple. It's the same as saying:

a = (35, 000)  # Which is also the same as (35, 0).

Yes, this is possible starting with python 3.6.

PEP 515 adds the ability to use underscores in numeric literals for improved readability. For example:

>>> 1_000_000_000_000_000
1000000000000000
>>> 0x_FF_FF_FF_FF
4294967295
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!