Open In App

Python | sympy.is_prime() method

Improve
Improve
Like Article
Like
Save
Share
Report

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

Last Updated : 08 Feb, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads