Thursday, October 9, 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
32346 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6715 POSTS0 COMMENTS
Nicole Veronica
11878 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6837 POSTS0 COMMENTS
Ted Musemwa
7095 POSTS0 COMMENTS
Thapelo Manthata
6790 POSTS0 COMMENTS
Umr Jansen
6791 POSTS0 COMMENTS