An ad-free and cookie-free website.
A Python tutorial on the beginner's first 8 Python math functions to learn before advancing to more difficult math in NumPy and Pandas modules.
Videos can also be accessed from our Full Stack Playlist 3 on YouTube.
Eight Python builtin math functions | Python for Beginners (4:51)
Welcome. Today's question: Which 8 math functions should Python beginners learn first?
I'm Paul, and here we cover data science, so it's important that we learn basic math functions before heading off to the exotic, fun and head-scratching stuff like Statistics.
So here we'll stick with functions built-in to Python with a review of 3 we covered earlier, then tack on 2 for calculations on single numbers, followed by 3 that operate on a range of numbers.
This closes out the 11-video Project 3 (Python for Beginners). Hang on for the end and I'll tell you what Project 4 is all about.
(Commands in Linux)
(Functions in Python)
Let's head to the Linux terminal and here's a file with all of the built-in functions in this version of Python.
Noted is where each function was introduced, and here in video 32, we're checking off absolute value, power, maximum, minimum and summation.
|abs() (32)||dict()||help(28)||min() (32)||setattr()|
|bin()||eval()||int() (27)||open()||str() (26)|
|bool()||exec()||isinstance()||ord() (26)||sum() (32)|
|bytes()||float() (27)||iter()||print() (26)||tuple()|
|complex()||hasattr()||max() (32)||round() (27)|
(Also See official documentation at the official python.org.)
For now we're working with two data types in math, we have integers, and when entered without a decimal place, Python assumes it's an integer.
We also have floats, or floating point numbers entered with a decimal.
So with 8 functions to cover; let's get cracking.
int(), views a float as an
It won't change it; it will just view it (as an integer).
float(), does the
opposite, view an integer as a float.
round(), and here we input
how many decimal places we'd like to round a number to, using an
optional argument after a comma, telling Python where you want it to
The default rounds to a whole number. And there's object help, if you forget how it works.
Function 4, is absolute value. Here's the help.
q to leave.
Here we input one number and it returns the absolute value, so
abs(x) which is negative 2, becomes
It works with floats too.
Function 5, Python power. Let's get in the habit of looking at help,
help(pow) in this case.
And let's do the two argument version.
So it goes 3 to the power of 2 is 9, and going the other way, 9 to the power of one-half, or the square root, is 3.0.
For function 6, let's set up a range of numbers, let's call them grades, and assign some percentile scores over a semester, like this.
I'll put them in what is called a list like this, and use
max() to find the highest grade of 99.
help() we can see there are two
ways to work with
max(), and here
we're using the second option, saving the first on iterables for later.
min() is done the same way.
No surprises there.
Function 8, summation or
how that works, and it won't work on text, which is obvious.
Let's throw the list of grades in and we get 442.
But that's more meaningful if we get an average, dividing by 5 and that gives us 88.4, eh, a B-plus.
On the topic of average, and other statistical calculations we won't have to put them together ourselves like this. Instead, in later videos we'll import modules allowing us to do linear algebra, regressions and all sorts of math with neat visualizations.
Also, if you're not familiar with my background, in a previous life, I managed $5 Billion in stock mutual funds in the US, so the subject matter expertise I'll bring to the table is in the financial markets.
So a number of projects will be geared to those aspiring to be financial engineers, quants and portfolio managers. We'll also use Python to analyze data for marketing, social media and more.
In the meantime, this concludes Project 3, and in Project 4 we'll kick off HTML and CSS for Beginners so we can create web pages to view all of our neat output in a browser.
And coding right in the Python Interpreter will be phased out as well. We'll work with multi-line files almost exclusively.
To be part of the fun, please subscribe and comment so others can learn from your insights, and your observations.
Have a nice day.
Check out other learning content at our YouTube Channel. Subscribe to our email list and follow @factorpad on Twitter so you don't miss new content.
A newly-updated free resource. Connect and refer a friend today.