Kis*_*ngh 1 python printf for-loop if-statement python-3.x
我了解 Java,所以我尝试在 for 块中写一个 if 块说,
for i in range(25):
if i == 9:
i = 18
print(i)
Run Code Online (Sandbox Code Playgroud)
此代码逻辑在 java 中有效,但在 python 中无效。我该怎么办?
使用两个范围和 的幂itertools
。
import itertools
for i in itertools.chain(range(1, 9), range(18,25)):
print(i)
Run Code Online (Sandbox Code Playgroud)