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



