Python | sympy.is_prime() method

In simpy 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 as prime number.

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

Code #1:



filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

False
True

Code #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

True


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.