我可以看到多个页面解释如何在python中格式化和打印数字,但有没有办法以可读的方式编写大数字代码?
speed_of_light = 299 792 458 # metres
dist_to_andromeda = 2,537,497 # light years
dia_of_earth_at_eq = 12_756_320 # metres
编辑:我发现最后一个在py36上运行,但对于那些使用py35的人来说有什么解决方案?除了评论之外,还有其他方法是多余的吗?
答案 0 :(得分:1)
从Python 3.6中有
dia_of_earth_at_eq = 12_756_320
是有效代码。
请参阅PEP 515: Underscores in Numeric Literals in What's new in Python 3.6