Kathryn explains some of the common built-in mathematical functions such as round(), abs(), and pow(). Round() takes a given number and returns the number rounded up or down depending on the input's value. Abs() calculates the absolute value of a given number. Pow() takes two inputs—a base and an exponent—and performs exponentiation on them. These functions can be helpful if you need to perform some simple math computations in your code that you don't want to full write out yourself.
- [Instructor] Let's talk about the round function.…The round function takes one whole or decimal number…and outputs an integer that represents that same number,…but rounded up or down, depending on its value.…So if the first decimal digit is four or below,…the number will be rounded down,…or, if the first decimal digit is five or above,…then the number will be rounded up.…This may be different on your computer,…depending on what version of Python you're using.…Going into the code, let's say…we create a variable called myGPA,…and we're going to have it equal 3.6.…
Now, what if we wanted to round our GPA up?…Well we could do this using the round function,…and so we could go print round myGPA,…and then we'll go ahead and print it out, and we get four.…If only this were true.…Now, we can also use this round function with ingredients,…and so, say we have amount of salt…equals 1.4,…and so say this represents pinches of salt,…but what is a point-four pinch of salt?…Well, we'd want to round down for this,…and so you could go print round amount of salt,…
- Working with logical and comparison operators
- Getting a list of numbers with the range() and list() functions
- Using mathematical functions such as round(), abs(), and pow()
- Calculating a given input's length
- Importing and using the math module
- Reading a user's command-line arguments
- Getting the current time
- Formatting dates and times with datetime
- Creating a timer
- Using urllib to get content from the Internet
- Using the JSON module to decode content
Skill Level Intermediate
1. Python: What's Built-In?
2. Python: Math
3. Python: Input/Output
4. Python: Date & Time, HTML Parsing, and HTTP
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.