问题
for n in range(2,5):
for x in range(2,n):
print(n,x)
Gives output as:
3 2
4 2
4 3
why the value of n start from 3 not 2?
回答1:
n
starts at three because range(2, 2)
is empty. Maybe you really want:
for n in range(2, 5):
for x in range(2, n + 1):
print(n, x)
Results:
2 2
3 2
3 3
4 2
4 3
4 4
来源:https://stackoverflow.com/questions/50575700/range-function-in-python