The Wayback Machine - https://web.archive.org/web/20221104123320/https://www.geeksforgeeks.org/python-sympy-isprime-method/
Skip to content
Related Articles

Related Articles

Python | sympy.isprime() method

View Discussion
Improve Article
Save Article
  • Last Updated : 25 Aug, 2021
View Discussion
Improve Article
Save Article

In simpy module, we can test whether a given number n is prime or not using sympy.isprime() 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 as prime number.

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

Code #1:  

Python3




# Python program to check prime number
# using sympy.isprime() method
 
# importing sympy module
from sympy import *
 
# calling isprime function on different numbers
isprime(30)
isprime(13)
isprime(2)

Output: 

False
True
True

Code #2:  

Python3




# Python program to check prime number
# using sympy.isprime() method
 
# importing sympy module
import sympy.ntheory as nt
 
# calling isprime function on different numbers
nt.isprime(30)
nt.isprime(13)
nt.isprime(2)

Output: 

False
True
True

 

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!