Monday, June 15, 2026
HomeLanguagessympy.stats.Binomial() function in Python

sympy.stats.Binomial() function in Python

With the help of sympy.stats.Binomial() method, we can create a Finite Random Variable representing a binomial distribution. 

A binomial distribution is the probability of a SUCCESS or FAILURE outcome in an experiment or survey that is repeated multiple times.

Syntax: sympy.stats.Binomial(name, n, p, succ=1, fail=0)

Parameters:
 name: distribution name
 n: Positive Integer, represents number of trials
 p: Rational Number between 0 and 1, represents probability of success
 succ: Represents event of success, by default is 1
 fail: Represents event of failure, by default is 0

Example #1 :

Python3




# Import sympy, Binomial, density
from sympy.stats import Binomial, density
  
# Using sympy.stats.Binomial() method
X = Binomial('X', 4, 1 / 3)
binDist = density(X).dict
  
print(binDist)


Output :

{0: 16/81, 1: 32/81, 2: 8/27, 3: 8/81, 4: 1/81}



Example #2 :

Python3




# Import sympy, Binomial, density
from sympy.stats import Binomial, density
  
# Using sympy.stats.Binomial() method
X = Binomial('X', 4, 1 / 3, 1 / 2)
binDist = density(X).dict
  
print(binDist)


Output :

{0: 16/81, 1/2: 32/81, 2: 1/81, 3/2: 8/81, 1: 8/27}



Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS