Learn the difference between type and instance as well as how to use the type() and isinstance() functions. Type() returns the type of one given input while isinstance() has two inputs and returns true or false whether or not the first input is an instance of the second input. Isinstance() accounts for some things that type() does not - so it is often better to use in situations that involve inheritance.
- [Narrator] Now let's learn about some functions…that are going to help us test for certain functionality.…The type function takes one input, any object,…and the output is the type of the given input.…So, it could be int, string, whatever type that object is.…So going to the code, let's just create a range,…say r, and we're going to have it be the range from zero to 30.…We learned about ranges in a previous video,…but let's just go ahead and print out…the fact that this is a range.…
And so here we get class range, because r is of type range.…We can also do this for different types of data.…So we could print out the type of a number.…It's going to be int because 10 is an integer.…We can also do this for strings,…and so we could go print type A,…and that's just one character string,…and then we'll have print type Hi there,…which is a bit of a longer string,…and then printing these out we get str str,…which both stand for strings.…
We'll see why this is useful later on.…The next function we're going to talk about is isinstance,…
- 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
Learning the Standard PHP Librarywith David Powers3h 24m 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.