If you allow the use of the standard library,

import math

xs = [0.5,0.7,0.3,0.2]     # values (must be floats!)
mean = sum(xs) / len(xs)   # mean
var  = sum(pow(x-mean,2) for x in xs) / len(xs)  # variance
std  = math.sqrt(var)  # standard deviation

If not, you need to approximate sqrt by hand. For example, you can use binary search or Newton's Method. Here's a wikipedia page for methods of doing so

Answer from duckworthd on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-statistics-stdev
stdev() method in Python statistics module - GeeksforGeeks
The stdev() function in Python's statistics module is used to calculate the standard deviation of a dataset. It helps to measure the spread or variation of values in a sample. Standard deviation (SD) measures the spread of data points around ...
Published: July 11, 2025
🌐
W3Schools
w3schools.com › python › ref_stat_stdev.asp
Python statistics.stdev() Method
The statistics.stdev() method calculates the standard deviation from a sample of data.
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.std.html
numpy.std — NumPy v2.6.dev0 Manual
Returns the standard deviation, a measure of the spread of a distribution, of the array elements.
🌐
Data Science Discovery
discovery.cs.illinois.edu › guides › Statistics-with-Python › calculating-std-in-python
Calculating Standard Deviation in Python - Data Science Discovery
September 29, 2022 - This guide will demonstrate the different ways to calculate standard deviation in Python so you can choose the method you need.
🌐
Enki
enki.com › post › how-to-calculate-standard-deviation-in-python
Enki | Blog - How to Calculate Standard Deviation in Python
Let's break down the code. We start by calculating the mean using Python's sum and len functions. Next, we calculate the variance by summing the squared differences between each data point and the mean. Finally, we take the square root of the variance to get the standard deviation.
Find elsewhere
🌐
W3Schools
w3schools.com › python › python_ml_standard_deviation.asp
Python Machine Learning Standard Deviation
A low standard deviation means that most of the numbers are close to the mean (average) value.
🌐
Python.org
discuss.python.org › python help
Statistics.stdev() does not agree with my own standard deviation calculation - Python Help - Discussions on Python.org
July 22, 2023 - Hello all, some might argue this ... possibly something to do with Python floats - though I’m not sure. I’ve written a small script that generates a set of ten numbers between one and ten inclusive and then calculates the standard deviation using an algorithm that I just ...
🌐
Codefinity
codefinity.com › courses › v2 › a849660e-ddfa-4033-80a6-94a1b7772e23 › 50bab4f9-b308-4ff0-b5d2-0989afa4ddd7 › dc1e3319-e615-4c3a-a575-a5504021442e
Learn Standard Deviation with Python | Variance and Standard Deviation
123456789101112 import pandas as pd import numpy as np df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/a849660e-ddfa-4033-80a6-94a1b7772e23/update/ds_salaries_statistics', index_col = 0) # Calculate the standard deviation using the function from the NumPy library std_1 = np.std(df['salary_in_usd']) # Calculate the standard deviation using the function from the pandas library std_2 = df['salary_in_usd'].std() print('The standard deviation using NumPy library is', round(std_1, 2)) print('The standard deviation using pandas library is', round(std_2, 2))
🌐
Reddit
reddit.com › r/learnpython › assignment help: calculating standard deviation
r/learnpython on Reddit: Assignment help: Calculating standard deviation
October 28, 2022 -
#Previous funtion
def compute_mean(my_list):
    number_list = my_list
    total = 0
    for number in number_list:
        total = total + float(number)
    return total / len(number_list)

#The function I'm working on
def compute_sd(my_list):
    list_of_numbers = my_list
    sum = 0
    for num in list_of_numbers:
        mean = my_list
        dev = num - mean
        var = sum((l-mean)**2 for l in list) / len(list)
        dev = math.sqrt(var)

    return dev

This is what I have so far, and I'm stumped.

In this step we will write a function (compute_sd) to calculate the standard deviation of the numbers in a list. It will receive a list of integer numbers as parameter and will return the standard deviation of the numbers in the given list. It will complete the task as follows:

· Use compute_mean function to calculate mean of the numbers in the list

· Initialize sum to 0

· Use definite loop (for num in list_of_numbers)

o Calculate deviation by subtracting mean from the num

o Calculate the square of the deviation

o Add the square of the deviation to sum

· Calculate the size of the list

· Divide sum by the size-1 to compute the result.

· Take the square root of the result to compute the standard deviation.

· Return the standard deviation of the numbers in the list.

🌐
AskPython
askpython.com › python › examples › mean-and-standard-deviation-python
Mean and Standard Deviation in Python - AskPython
April 18, 2026 - Population standard deviation divides by N. Sample standard deviation divides by N-1. Mixing these up produces wrong results. Python’s statistics module calculates sample standard deviation by default (ddof=1).
🌐
Educative
educative.io › answers › what-is-the-statisticsstdev-method-in-python
What is the statistics.stdev() method in Python?
This method is unlike the statistics.pstdev(), which calculates the standard deviation of an entire population; instead, it only computes the standard deviation from a sample of data.
🌐
Onestopdataanalysis
onestopdataanalysis.com › home › standard deviation in python – the easiest way
Standard Deviation in Python - The Easiest Way to Calculate it
March 7, 2020 - In case you have numpy install in your machine, you can also compute the Standard Deviation in Python using numpy.std.
🌐
YouTube
youtube.com › watch
Python - Standard Deviation - YouTube
Instructional video on determining the standard deviation with Python.Companion website: https://PeterStatistics.comJupyter Notebook used in video: https://b...
Published: July 6, 2020
🌐
Vitoshacademy
vitoshacademy.com › python-understanding-standard-deviation
Python – Understanding Standard Deviation – Useful code
Useful code Programming with VBA, C# and Python · Menu · Vitosh Posted on August 6, 2024 Posted in VBA \ Excel · So, what exactly is standard deviation? In simple terms, it’s a measure of how spread out the numbers in a dataset are from the mean or average.
🌐
Standarddeviationcalculator
standarddeviationcalculator.app › learn › excel-python
Calculate Standard Deviation in Excel & Python | Standard Deviation Calculator
April 10, 2026 - import numpy as np data = [4, 8, 6, 5, 3] # Population standard deviation (default) pop_sd = np.std(data) print(f"Population SD: {pop_sd}") # 1.720 # Sample standard deviation sample_sd = np.std(data, ddof=1) print(f"Sample SD: {sample_sd}") # 1.924
🌐
Python
docs.python.org › 3 › library › statistics.html
statistics — Mathematical statistics functions
Return the population standard deviation (the square root of the population variance).
🌐
scikit-learn
scikit-learn.org › stable › modules › cross_validation.html
3.1. Cross-validation: evaluating estimator performance — scikit-learn 1.9.1 documentation
>>> print("%0.2f accuracy with a standard deviation of %0.2f" % (scores.mean(), scores.std())) 0.98 accuracy with a standard deviation of 0.02