Python Object Types
- 03:42
Learn about Python as an object-oriented programming language, covering basic data types like integers, floats, strings, and booleans, and the importance of these elements for data science and machine learning applications.
Downloads
Glossary
Anaconda Data Types PythonTranscript
Let's start by opening up the Anaconda Navigator and then our Jupyter Notebook.
And once you have that open, go ahead and navigate to the Jupyter Notebook file for Python Fundamentals two, which should be just above this lesson.
Let's take a second and talk about what Python actually is. So Python is what's called an object oriented programming language, just like Java and C++. And what that means is that Python is organized around what's called objects or these pieces of data that interact with each other based on the code. You're already familiar with a few different types of objects based on the last lesson, including integers, which are these whole numbers with no decimal point. Floats, which are numbers with a decimal point and strings, which is text surrounded by a single quote or a double quote. And now notice if I have what would be a float, this 2.0 down here, and I surround it by single quotes or double quotes, it's still going to be a string, despite the fact that it's a number inside that string. And Python is going to treat that as text, just as if you were in Excel and you put a single quote in front of a number. Excel is going to treat that number as text and the exact same way Python is going to treat this number as text because we formatted it as a string. Also, notice that just because you have text does not mean that Python will interpret it as a string. If I write text down here and I don't surround it by single or double quotes, Python is not going to interpret it as a string and it's not gonna treat it in the way that I want it to.
And you also saw this type of object called a Boolean. And what a Boolean is is any kind of inequality using these comparison operators. So 10 is greater than 5 or 100 is less than 1 is this is gonna give me a true output, like down here a hundred is lesson one is gonna give me a false output. So both these inequality equations, using these comparison operators as well as their true and false outputs are Boolean objects. Now another thing, I mentioned this in the last lesson, be very careful when you're checking equality. So if I wanna know that seven is equal to seven, you must use the double equal sign. Using a single equal sign, as you saw, is a way to define a variable. And Python treats those two things very differently. So you use a single equal symbol to define a variable. If you want to compare to numbers, you use a double equal sign. So you're already very familiar with four super important object types, integers, floats, strings, and Boolean. And you're gonna see these over and over again in all of your work in data science and machine learning.
As you're writing your own Python code and creating custom machine learning algorithms, you're often going to want to check the type of an object. And this is going to be important if you have a type that you can see like this. But also if an object is stored in a variable as a float or as a string, you might want your code to treat that differently and be able to say, if this object is a float, then I want you to treat it a certain way. If it's a string, then I want you to treat it a different way. So the way that we accomplish that in Python is using the type function. So if I go up here and I execute this, I have all different types of objects. When I execute that cell, it's gonna give me all of the object types of all of those objects.