📜  Python| simpy.primerange() 方法

📅  最后修改于: 2022-05-13 01:55:26.892000             🧑  作者: Mango

Python| simpy.primerange() 方法

在 simpy 模块中,我们可以使用 sympy.primerange()函数获取 [a, b) 范围内所有素数的列表。

Syntax:  sympy.primerange()
Parameter:  range a and b
Return:  a list of all primes in given range

代码#1:

Python3
# Python program to get prime number range
# using sympy.primerange() method
 
# importing sympy module
from sympy import *
 
# calling primerange function on different numbers
list(primerange(7, 30))
list(primerange(0, 100))


Python3
# Python program to get the range prime number
# using sympy.primerange() method
 
# importing sympy module
import sympy.ntheory as nt
 
# calling primerange function on range
list(nt.primerange(2, 31))


输出:

代码#2:

Python3

# Python program to get the range prime number
# using sympy.primerange() method
 
# importing sympy module
import sympy.ntheory as nt
 
# calling primerange function on range
list(nt.primerange(2, 31))

输出:

[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]