我在Java:的Java爲Python的例子循環
public static void main(String[] args) {
int x = 10;
for(int i = 0; i <= x; i++){
System.out.println("i = " + i + "******");
for(int j = 0; j <= i; j++){
System.out.print("j = " + j + " ");
}
}
與輸出:
run:
i = 0******
j = 0 i = 1******
j = 0 j = 1 i = 2******
j = 0 j = 1 j = 2 i = 3******
j = 0 j = 1 j = 2 j = 3 i = 4******
j = 0 j = 1 j = 2 j = 3 j = 4 i = 5******
j = 0 j = 1 j = 2 j = 3 j = 4 j = 5 i = 6******
j = 0 j = 1 j = 2 j = 3 j = 4 j = 5 j = 6 i = 7******
j = 0 j = 1 j = 2 j = 3 j = 4 j = 5 j = 6 j = 7 i = 8******
j = 0 j = 1 j = 2 j = 3 j = 4 j = 5 j = 6 j = 7 j = 8 i = 9******
j = 0 j = 1 j = 2 j = 3 j = 4 j = 5 j = 6 j = 7 j = 8 j = 9 i = 10******
j = 0 j = 1 j = 2 j = 3 j = 4 j = 5 j = 6 j = 7 j = 8 j = 9 j = 10
我想實現的Python for循環究竟效果:
x = 10
for i in range(0, x, 1):
print("i = ", i, "*******")
for j in range(0, i, 1):
print("j = ", j, end="")
輸出:
i = 0 *******
i = 1 *******
j = 0i = 2 *******
j = 0j = 1i = 3 *******
j = 0j = 1j = 2i = 4 *******
j = 0j = 1j = 2j = 3i = 5 *******
j = 0j = 1j = 2j = 3j = 4i = 6 *******
j = 0j = 1j = 2j = 3j = 4j = 5i = 7 *******
j = 0j = 1j = 2j = 3j = 4j = 5j = 6i = 8 *******
j = 0j = 1j = 2j = 3j = 4j = 5j = 6j = 7i = 9 *******
j = 0j = 1j = 2j = 3j = 4j = 5j = 6j = 7j = 8
我開始學習python,我知道java在中級水平,不能開始思考那些pyhon循環。 Python的3.6
'九月= 「」,結束=」「'應該在你的情況下工作。參數'sep'之間的默認分隔被設置爲'「」'。 Python範圍不包含最終值,因此循環將不得不轉到'x + 1'和'i + 1' –