Learn Programming and technology with ease @ developerpublish.com

HomePythonPython Program to Calculate Standard Deviation

# Python Program to Calculate Standard Deviation

In this python tutorial, you will learn how to Calculate Standard Deviation with built in functions of the python programming language.

## How to Calculate Standard Deviation?

Standard deviation isÂ the measure of dispersion of a set of data from its mean. Standard Deviation is calculated by :

where x1, x2, x3, xn are observed values in sample data, is the mean value of observations and N is the number of sample observations

Letâ€™s take a look at the source code,Â  here the values are assigned in the code, the built in functions carry out the function.

# Python Program to Calculate Standard Deviation

import statistics

sample = [1, 2, 3, 4, 5]

print("Standard Deviation of sample is % s "
% (statistics.stdev(sample)))


OUTPUT:

Standard Deviation of sample is 1.5811388300841898
1. At the start we use the import statistics where the import keyword is used to import the values which the variableÂ  statistics holds
2. Next, we create a simple set of data containing integers [1, 2, 3, 4, 5] and assign the values to the variable sample Â respectively.
3. We declare a print function we display the statement ("Standard Deviation of sample is % s " % (statistics.stdev(sample))), where the in the place of the variable s, the standard deviation of the values in the variable sample will be displayed.

NOTE:

• The %s operatorÂ lets you add a value into a Python string
• Â The stdev() is a built in function which can be used to calculate the standard deviation.
• TheÂ printÂ statement is followed by a period, to initiate the format function.
• The print statement/string to be displayed in enclosed inÂ double quotes.

### You May Also Like

#### Python Program to Remove Duplicates from a Linked List

In this Python program, we will create a singly linked list and remove duplicate elements from it. A linked list...

#### Python Program to Solve the Celebrity Problem

This Python program solves the Celebrity Problem by finding a person who is known by everyone but does not know...

#### Python Program to Solve n-Queen Problem with Recursion

This Python program uses a recursive approach to solve the n-Queens problem. It explores all possible combinations of queen placements...