Saturday, September 6, 2025
HomeLanguagesPython | sympy.is_prime() method

Python | sympy.is_prime() method

In the sympy module, we can test whether a given number n is prime or not using sympy.is_prime() function. For n < 2^64 the answer is definitive; larger n values have a small probability of actually being pseudoprimes. 

Note that Negative numbers (e.g. -13) are not considered prime numbers.

Syntax:  sympy.is_prime()
Parameter:  n; number to be tested
Return:  bool value result 

Code #1:  

Python3




# Python program to check prime number
# using sympy.is_prime() method
 
# importing sympy module
from sympy import *
 
# calling isprime function on different numbers
geek1 = simplify(30).is_prime
geek2 = simplify(13).is_prime
 
print(geek1)
print(geek2)


Output: 

False
True

Code #2:  

Python3




# Python program to check prime number
# using sympy.is_prime() method
 
# importing sympy module
from sympy import *
 
# calling isprime function on different numbers
geek1 = simplify(2).is_prime
geek2 = simplify(-2).is_prime
 
print(geek1)
print(geek2)


Output: 

True
False
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32270 POSTS0 COMMENTS
Milvus
82 POSTS0 COMMENTS
Nango Kala
6639 POSTS0 COMMENTS
Nicole Veronica
11803 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11869 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7029 POSTS0 COMMENTS
Thapelo Manthata
6705 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS