【python】官网例子
地址:https://docs.python.org/3/tutorial/controlflow.html
>>> for n in range(2, 10):
... for x in range(2, n):
... if n % x == 0:
... print(n, 'equals', x, '*', n//x)
... break
... else:
... # loop fell through without finding a factor
... print(n, 'is a prime number')
...
2 is a prime number
3 is a prime number
4 equals 2 * 2
5 is a prime number
6 equals 2 * 3
7 is a prime number
8 equals 2 * 4
9 equals 3 * 3
为什么range(2,2)不会报错,它返回的是一个空迭代器,for循环作用于空的迭代器上一次也不会执行,而是直接结束
常常感恩