From the course: Learning the Python 3 Standard Library

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Factorial, square root, and GCD

Factorial, square root, and GCD - Python Tutorial

From the course: Learning the Python 3 Standard Library

Factorial, square root, and GCD

- [Instructor] Let's dive deeper into the math module. First, we have to import math because we have to have our module we're working with. And we are going to start off by looking at the factorial function. To use it, you just do math.factorial, and it'll get the factorial of any number you want. And so to start off, we'll go 3, and then we'll go ahead and print this whole thing out. And so this will just give us the factorial of 3, and that would be 3 times 2 times 1, which will give us 6 in the output. Another function that's just built into the math module, ready for us to use is square root. We'll go print math. the square root, and so sqrt, and then any number you want to get the square root of. Here, we'll just do 64. And the square root of 64 is 8, and that's what we get in the output. Another thing Python can do is help us find the greatest common denominator between two numbers. The name of the method we use…

Contents