最佳答案
要回答您的问题,请查看 python 3.6 documentation对于 isdigit
方法。
Return true if all characters in the string are digits and there is at least one character, false otherwise.
由于下划线不是数字,因此新格式无法与 isdigit
的当前实现很好地配合。正如我之前评论的,立即解决的方法是: str.replace("_", "").isdigit()
其中 str 是包含新格式化数字的字符串,同时避免使用 int
出现 try- except block 。
关于Python 新推出的数字文字(例如 234_432)不能与 .isdigit() 一起使用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45396339/