Content · Programming · Python

Python statistics.multimode() Function: Usage and Examples

Return all values tied for the highest frequency.

2 views Published Oct 17, 2026 Updated Oct 18, 2026 Admin

Return all values tied for the highest frequency.

What It Does and Why It Matters


multimode(data) returns a list of most frequent values in first-encountered order, or an empty list for empty input.

statistics.multimode() has documented sample-size and input assumptions that must be checked before use.

Step-by-Step Example


Start with the complete example below. Read the inputs and predict what the final print statement will show before you run it.

import statistics
print(statistics.multimode(["A", "B", "B", "A", "C"]))

How the Code Works


  • The imports make these standard-library tools available: statistics.
  • The print calls display the results. Compare these results with the method’s documented return type and the input used.
  • The calculation uses the exact sample values shown in the code. Interpret the result using the required dataset assumptions (for example, paired values, positive numbers or an adequate sample size) rather than treating every numerical result as interchangeable.

Expected output:

['A', 'B']

For the demonstrated inputs, Python displays "['A', 'B']". This result follows from the operation described above; change one input at a time to understand which rule matters.

What to Notice


Pay attention to the accepted input types, the returned value and the boundary behavior. Predict what changes if you replace the example input with an empty, zero, negative or missing value, where that value is meaningful for this operation.

If the task uses a library function, inspect its documented exceptions and return type before reusing it inside a larger function.

Where You Would Use This


Use this in calculations, data summaries, simulations or validation when the numerical assumptions match the task. Check input domains, units and precision before interpreting a result. A single example output does not prove a statistical conclusion.

Practice Exercise


Find all popular answers in a small survey.

Before running your edited example, write down the result you expect. Then test at least one valid boundary or deliberately invalid value, using appropriate exception handling where necessary.

Reference: official Python documentation for the complete API contract and version notes.

Common Beginner Mistakes


  • Assuming multimode() returns a single item even when several values tie.
  • Using a numeric result without checking empty data, invalid ranges, precision and the meaning of its units.

Key Takeaways


  • Return all values tied for the highest frequency.
  • multimode(data) returns a list of most frequent values in first-encountered order, or an empty list for empty input.
  • Find all popular answers in a small survey.
Share this resourceSend this page to someone who may find it useful.