Thursday, October 16, 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
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS