简体   繁体   English

为什么 Python3.6 允许这个 float('20200407_2') ?

[英]Why is this float('20200407_2') allowed in Python3.6?

Does anyone understand why Python 3.6 allows this string '20200407_2' code to be converted?有谁明白为什么 Python 3.6 允许转换此字符串'20200407_2'代码?

>>> float('20200407_2')
202004072.0

Python 2.7 does not allow it. Python 2.7 不允许。

>>> float('20200407_2')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for float(): 20200407_2

From the docs :文档

Changed in version 3.6: Grouping digits with underscores as in code literals is allowed.在 3.6 版更改: 允许在代码文字中使用下划线对数字进行分组。

I think it answers your question.我认为它回答了你的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM