A prime number is a natural number greater than 1 whose only factors are 1 and the number itself. 2 is the only even Prime number. We can represent any prime number with '6n+1' or '6n-1' (except 2 and 3) where n is a natural number.
primePy is that library of Python which is used to compute operations related to prime numbers. It will perform all the functions in less time with the help of the functions of this primePy module.
Installing Library
This module does not come built-in with Python. You need to install it externally. To install this module type the below command in the terminal.
pip install primePy
Functions of primePy
1. primes.check(n): It will return True if 'n' is a prime number otherwise it will return False.
Example:
Python3
# Importing primes function
# From primePy Library
from primePy import primes
print(primes.check(105))
print(primes.check(71))
Output:
False
True
2. primes.factor(n): It will return the lowest prime factor of 'n'.
Example:
Python3
# Importing primes function
# From primePy Library
from primePy import primes
a = primes.factor(15)
print(a)
a = primes.factor(75689456252)
print(a)
Output:
3
2
3. primes.factors(n): It will return all the prime factors of 'n' with repetition of factors if exist.
Example:
Python3
# Importing primes function
# From primePy Library
from primePy import primes
a = primes.factors(774177)
print(a)
a = primes.factors(15)
print(a)
Output:
[3, 151, 1709]
[3, 5]
4. primes.first(n) : It will return first 'n' prime numbers.
Example:
Python3
# Importing primes function
# From primePy Library
from primePy import primes
a = primes.first(5)
print(a)
a = primes.first(10)
print(a)
Output:
[2, 3, 5, 7, 11]
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
5. primes.upto(n): It will return all the prime numbers less than or equal to 'n'.
Example:
Python3
# Importing primes function
# From primePy Library
from primePy import primes
a = primes.upto(17)
print(a)
a = primes.upto(100)
print(a)
Output:
[2, 3, 5, 7, 11, 13, 17]
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
6. primes.between(m, n): It will return all the prime numbers between m and n.
Example:
Python3
# Importing primes function
# From primePy Library
from primePy import primes
a = primes.between(4, 15)
print(a)
a = primes.between(25, 75)
print(a)
Output:
[5, 7, 11, 13]
[29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73]
7. primes.phi(n): It will return the number of integers less than 'n' which have no common factor with n.
Example:
Python3
# Importing primes function
# From primePy Library
from primePy import primes
a = primes.phi(5)
print(a)
a = primes.phi(10)
print(a)
Output:
4
4
Similar Reads
Python Module Index Python has a vast ecosystem of modules and packages. These modules enable developers to perform a wide range of tasks without taking the headache of creating a custom module for them to perform a particular task. Whether we have to perform data analysis, set up a web server, or automate tasks, there
4 min read
Python Fire Module Python Fire is a library to create CLI applications. It can automatically generate command line Interfaces from any object in python. It is not limited to this, it is a good tool for debugging and development purposes. With the help of Fire, you can turn existing code into CLI. In this article, we w
3 min read
Python Modules Python Module is a file that contains built-in functions, classes,its and variables. There are many Python modules, each with its specific work.In this article, we will cover all about Python modules, such as How to create our own simple module, Import Python modules, From statements in Python, we c
7 min read
Import module in Python In Python, modules allow us to organize code into reusable files, making it easy to import and use functions, classes, and variables from other scripts. Importing a module in Python is similar to using #include in C/C++, providing access to pre-written code and built-in libraries. Pythonâs import st
3 min read
Basics Of Python Modules A library refers to a collection of modules that together cater to a specific type of needs or application. Module is a file(.py file) containing variables, class definitions statements, and functions related to a particular task. Python modules that come preloaded with Python are called standard li
3 min read
Python Math Module Math Module consists of mathematical functions and constants. It is a built-in module made for mathematical tasks. The math module provides the math functions to deal with basic operations such as addition(+), subtraction(-), multiplication(*), division(/), and advanced operations like trigonometric
13 min read