我想知道为什么以下变量被视为数字?
a = 1_000_000
print (a)
1000000
不应该print(a)
return 1_000_000
?
使用 Python 3.6(以及PEP-515 https://www.python.org/dev/peps/pep-0515/)引入了一种新的大数字方便表示法,它允许您在数字文字中划分数字组,以便更容易阅读它们。
使用示例:
a = 1_00_00 # you do not need to group digits by 3!
b = 0xbad_c0ffee # you can make fun with hex digit notation
c = 0b0101_01010101010_0100 # works with binary notation
f = 1_000_00.0
print(a,b,c,f)
10000
50159747054
174756
100000.0
print(int('1_000_000'))
print(int('0xbad_c0ffee', 16))
print(int('0b0101_01010101010_0100',2))
print(float('1_000_00.0'))
1000000
50159747054
174756
100000.0
A = 1__000 # SyntaxError: invalid token
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)