下划线表示什么意思?
我想知道为什么以下变量被视为数字?
a = 1_000_000print (a)
1000000
不应该print(a)
回来1_000_000
吗?
回答:
在Python
3.6(和PEP-515)中,引入了一个新的大数字便捷表示法,它使您可以在数字文字中划分数字组,以便于阅读。
使用示例:
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
以上是 下划线表示什么意思? 的全部内容, 来源链接: utcz.com/qa/398783.html