The % (modulo) operator yields the remainder from the division of the
first argument by the second. The numeric arguments are first
converted to a common type. A zero right argument raises the
ZeroDivisionError exception. The arguments may be floating point
numbers, e.g., 3.14%0.7 equals 0.34 (since 3.14 equals 4*0.7 + 0.34.)
The modulo operator always yields a result with the same sign as its
second operand (or zero); the absolute value of the result is strictly
smaller than the absolute value of the second operand.
第一位是
range(13,5,-1)
,它只是从13
向后计数到6
。下一位是i%2 != 0
。i%2 == 0
相当于说if even
,或者“如果这个数字可以被2除而没有余数”,所以你的陈述是说“if odd
”(这显然与“if not even
”相同)。你知道吗基本上,循环是从13开始打印奇数,然后减少到6(但是6是偶数,所以不能打印)
这条线的意思是“如果i除以2后的余数不等于0”,所以它检查i是否为奇数。for循环正在倒计时1,但是if语句跳过打印偶数。你知道吗
%是模运算符。从docs:
相关问题 更多 >
编程相关推荐