Current location - Training Enrollment Network - Mathematics courses - How to write the sum and average of four numbers in python?
How to write the sum and average of four numbers in python?
As follows:

s = [ 1,2,3,4]

print(sum(s),sum(s)/len(s)) # 10 2.5

In the Python standard library, there are special mathematical statistical functions, which are in the statistical module. This module provides a function to calculate the mathematical statistics of real-valued data.

This module is not a competitive product of third-party libraries such as NumPy and SciPy, nor is it a full-featured statistical software package for professional statisticians such as Minitab, SAS and Matlab. This module is aimed at the level of graphics and scientific calculators.

Of course, in addition to professional third-party libraries and Python standard libraries, we can also write sums and averages in Python based on the knowledge learned in primary and secondary schools and Python operator knowledge.

Python was designed by Guido van Rossum of the Netherlands Institute of Mathematics and Computer Science in the early 1990s as a substitute for a language called ABC.

Python provides efficient high-level data structures and can also be used for simple and effective object-oriented programming. Python's syntax and dynamic types, as well as the nature of explanatory language, make it a programming language for writing scripts and developing applications quickly on most platforms. With the continuous updating of the version and the addition of new language functions, it is gradually used for the development of independent large-scale projects.

Python interpreters are easy to extend. You can use C or C++ (or other languages that can be called through C) to extend new functions and data types.

Python can also be used as an extension language in customizable software. Python's rich standard library provides source code or machine code suitable for all major system platforms.

In 2002110/0, Tiobe, the compiler of language popularity index, crowned Python as the most popular programming language, placing it above Java, C and JavaScript for the first time in 20 years.