Saturday, October 18, 2025
HomeLanguagesPython | sympy.bernoulli() method

Python | sympy.bernoulli() method

With the help of sympy.bernoulli() method, we can find the Bernoulli number and Bernoulli polynomial in SymPy.

bernoulli(n) –

Syntax: bernoulli(n)

Parameter:
n – It denotes the nth bernoulli number.

Returns: Returns the nth bernoulli number.

Example #1:




# import sympy 
from sympy import * n = 4
print("Value of n = {}".format(n))
   
# Use sympy.bernoulli() method 
nth_bernoulli = bernoulli(n)  
      
print("Value of nth bernoulli number : {}".format(nth_bernoulli))  


Output:

Value of n = 4
Value of nth bernoulli number : -1/30

bernoulli(n, k) –

Syntax: bernoulli(n, k)

Parameter:
n – It denotes the order of the bernoulli polynomial.
k – It denotes the variable in the bernoulli polynomial.

Returns: Returns the expression of the bernoulli polynomial or its value.

Example #2:




# import sympy 
from sympy import * n = 5
k = symbols('x')
print("Value of n = {} and k = {}".format(n, k))
   
# Use sympy.bernoulli() method 
nth_bernoulli_poly = bernoulli(n, k)  
      
print("The nth bernoulli polynomial : {}".format(nth_bernoulli_poly))  


Output:

Value of n = 5 and k = x
The nth bernoulli polynomial : x**5 - 5*x**4/2 + 5*x**3/3 - x/6

Example #3:




# import sympy 
from sympy import * n = 4
k = 3
print("Value of n = {} and k = {}".format(n, k))
   
# Use sympy.bernoulli() method 
nth_bernoulli_poly = bernoulli(n, k)  
      
print("The nth bernoulli polynomial value : {}".format(nth_bell_poly))  


Output:

Value of n = 4 and k = 3
The nth bernoulli polynomial value : 10*x1**2*x3 + 15*x1*x2**2
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS