Python | sympy.partition() method
With the help of sympy.partition() method, we can find Partition number in SymPy.
partition(n) -
The Partition numbers are a sequence of integers pn that represent the number of distinct ways of representing n as a sum of natural numbers (with order irrelevant). The generating function for pn is given by –
.
Syntax: partition(n)
Parameter:
n – It denotes the number upto which partition number is to be calculated.Returns: Returns the nth partition number.
Example #1:
# import sympy from sympy import * n = 7print("Value of n = {}".format(n)) # Use sympy.partition() method nth_partition = partition(n) print("Value of nth partition number : {}".format(nth_partition)) |
Output:
Value of n = 7 Value of nth partition number : 15
Example #2:
# import sympy from sympy import * n = 10print("Value of n = {}".format(n)) # Use sympy.partition() method n_partition = [partition(x) for x in range(1, 11)] print("N partition number are : {}".format(n_partition)) |
Output:
Value of n = 10 N partition number are : [1, 2, 3, 5, 7, 11, 15, 22, 30, 42]
Recommended Posts:
- class method vs static method in Python
- Python | set() method
- Python | os.dup() method
- Python | next() method
- Python | after method in Tkinter
- Python | sys.getrecursionlimit() method
- Python PIL | eval() method
- Python | sympy.rf() method
- Python | os.readlink() method
- Python | os.getpgid() method
- Python | sys.getdefaultencoding() method
- Python | os.tcgetpgrp() method
- Python PIL | ImagePalette() Method
- Python | sympy.ff() method
- Python | sympy.nT() method
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.


