# statistics.median() Function in Python – How to Apply (Example Code)

On this page you’ll learn how to use the statistics.median function in the Python programming language.

## Creation of Example Data

x = [1, 3, 3, 7, 1, 3, 5, 1, 2, 2, 1, 2, 1, 3, 1, 7] # Constructing a list in Python print(x) # Displaying the example list # [1, 3, 3, 7, 1, 3, 5, 1, 2, 2, 1, 2, 1, 3, 1, 7] |

x = [1, 3, 3, 7, 1, 3, 5, 1, 2, 2, 1, 2, 1, 3, 1, 7] # Constructing a list in Python print(x) # Displaying the example list # [1, 3, 3, 7, 1, 3, 5, 1, 2, 2, 1, 2, 1, 3, 1, 7]

## Example: Applying median() Function of statistics Module

import statistics # Import statistics |

import statistics # Import statistics

print(statistics.median(x)) # Get median of list # 2.0 |

print(statistics.median(x)) # Get median of list # 2.0