Thursday, June 11, 2026
HomeLanguagessympy.stats.variance() function in Python

sympy.stats.variance() function in Python

In mathematics, the variance is the way to check the difference between the actual value and any random input, i.e variance can be calculated as a squared difference of these two values. With the help of sympy.stats.variance() method, we can calculate the value of variance by using this method.

Syntax : sympy.stats.variance(value)

Return : Return the value of variance.

Example #1 :
In this example we can see that by using sympy.stats.variance() method, we are able to calculate the value of variance using this method.




# Import Sympy and variance
from sympy.stats import P, variance, Die
  
X, Y = Die('X', 5), Die('Y', 3)
  
# Using stats.variance() method
gfg = variance(X + Y)
  
print(gfg)


Output :

8/3

Example #2 :




# Import Sympy and variance
from sympy.stats import P, variance, Die
  
X, Y = Die('X', 2), Die('Y', 4)
  
# Using stats.variance() method
gfg = variance(X * Y)
  
print(gfg)


Output :

75/16
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
6896 POSTS0 COMMENTS
Nicole Veronica
12012 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
6963 POSTS0 COMMENTS