W3School TIY Editor

  • W3School 在线教程
  • 改变方向
  • 暗黑模式
​x
 
# 导入统计库
import statistics
​
# 计算众数
print(statistics.mode([1, 3, 3, 3, 5, 7, 7, 9]))  # 数值型众数计算
print(statistics.mode([1, 1, -3, 3, 7, -9]))  # 含负数的众数计算
print(statistics.mode(['red', 'green', 'blue', 'red']))  # 字符串型众数计算