Arithmatic Operators
Arithmatic Operators
MATHEMATICAL
OPERATIONS IN PYTHON
ENGR 102 – Introduction to Engineering
2 Mathematical Operations
Python includes the most basic mathematical
operations. Other math functions will be
accessed by importing the NumPy package
Multiplication: *
Division: /
Modulus: %
Exponentiation: **
Floor division: //
list
str
Python packages
Libraries consisting of multiple modules, or individual Python files
Modules within a package define
Data types
Functions
Must install a package before we can use it
Anaconda distribution includes all the packages we will need
Must import a package in our code before we can use it
Use the import function
exp(x) – exponential: 𝑒𝑒 𝑥𝑥
>>> y = np.exp(4.1)
60.3403
>>> e = np.exp(1)
2.71828
Infinity
(∞): inf
Not-a-number: NaN or nan
Both inf and nan often result from algorithmic errors
15
− ln 100
15
𝜋𝜋2 +ln2 100
12
2 1 − 𝑒𝑒 −0.1⋅8 cos 2𝜋𝜋 ⋅ 12 ⋅ 8
3