在Python 2.7和3.x,为什么整数除法给我一个不正确的数量由数除以时0 < x < 1?
负数-1 < x < 0甚至可以正常工作:
>>> 1//.1
9.0
>>> 1//-.1
-10.0
Run Code Online (Sandbox Code Playgroud)
我理解带负数(或正数)的整数除法向负无穷大舍入,但我认为1//.1应该导致10.0因为1可以除以.1余数.
Azure 需要多个 ID 来创建应用程序 ServicePrincipal 凭据。
有什么之间的区别client id和tenant id?
为什么 Azure 需要单独的 ID?
如何简化这个if语句?这是一个加号:http: //i.stack.imgur.com/PtHO1.png
如果语句完成,则在x和y坐标处设置块.
for y in range(MAP_HEIGHT):
for x in range(MAP_WIDTH):
if (x%5 == 2 or x%5 == 3 or x%5 == 4) and \
(y%5 == 2 or y%5 == 3 or y%5 == 4) and \
not(x%5 == 2 and y%5 == 2) and \
not(x%5 == 4 and y%5 == 2) and \
not(x%5 == 2 and y%5 == 4) and \
not(x%5 == 4 and y%5 == 4):
...
Run Code Online (Sandbox Code Playgroud) 我试图使用正则表达式的一部分作为正则表达式的后续部分的输入.
到目前为止我所做的(没有断言):
import re
regex = re.compile(r"(?P<length>\d+)(\d){(?P=length)}")
assert bool(regex.match("3123")) is True
assert bool(regex.match("100123456789")) is True
Run Code Online (Sandbox Code Playgroud)
打破这一点,第一个数字表示之后应该匹配多少个数字.在第一个断言中,我得到一个3,作为第一个字符,这意味着之后应该有正好三个数字,否则有超过9个数字.如果超过9位,则需要展开第一组并检查其余数字.
正则表达式3(\d){3}将正确匹配第一个断言,但是我无法使正则表达式与大括号{}被赋予正则表达式反向引用的一般情况相匹配:{(?P=length)}
用re.DEBUG我得到的标志调用正则表达式:
subpattern 1
max_repeat 1 4294967295
in
category category_digit
subpattern 2
in
category category_digit
literal 123
groupref 1
literal 125
Run Code Online (Sandbox Code Playgroud)
看起来braces {(123)和}(125)在它们内部有反向引用时被解释为文字.
当没有反向引用时,例如{3},我可以看到它{3}被解释为max_repeat 3 3
使用反向引用作为正则表达式的一部分可能吗?