Testing divisibility by multiple numbers

后端 未结 5 1628
灰色年华
灰色年华 2021-01-13 03:46

In Python, is there a way to test if a number is divisible by multiple numbers without writing out the modulo operation for each factor?

More specifically, is there

5条回答
  •  广开言路
    2021-01-13 03:58

    Useall()and a Generator Expression:

    if all(i % n == 0 for n in range(11, 101)):
        print(i)
    

提交回复
热议问题