您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何对Python整数文字使用数字分隔符?

如何对Python整数文字使用数字分隔符?

几年后更新:Python 3.6现在支持PEP515,因此您可以使用_来提高浮点数和整数文字的可读性。

Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 1_1000
11000
>>>

作为历史参考,您可以查看严格定义python2.7python3.5 …的词法分析。

对于python3.6.0a2及更早版本,您应该收到类似于以下内容错误消息:

Python 3.6.0a2 (v3.6.0a2:378893423552, Jun 13 2016, 14:44:21) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 1_000
  File "<stdin>", line 1
    1_000
        ^
SyntaxError: invalid Syntax
>>> amount = 10_000_000.0
  File "<stdin>", line 1
    amount = 10_000_000.0
                      ^
SyntaxError: invalid Syntax
python 2022/1/1 18:33:07 有213人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶