你将如何在 python 中打印数字 1、2、3、4、5、6、7、8、18、19、20、21、22、23、24?

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 中无效。我该怎么办?

Mat*_*ias 7

使用两个范围和 的幂itertools

import itertools

for i in itertools.chain(range(1, 9), range(18,25)):
    print(i)
Run Code Online (Sandbox Code Playgroud)