Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想知道您是否可以根据列表中的所有数字检查一个数字,例如:
if n % mylist == 0: print "Not Prime"
如果你想知道,这是这个问题的延续,我希望没有关于问题频率的任何规则......:/
if any(n % x == 0 for x in mylist): print "Not Prime"
...甚至更短:
if not all(n % x for x in mylist): print "Not prime"
(虽然我更喜欢 jamylak 的版本 - 显式优于隐式)