Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please refer to our video player troubleshooting guide for assistance.

Instantiating an Object

00:00 Once you have a class, you can then instantiate it. So in this example on-screen right now, you have class Point, and you’re passing, so it’s just a blank class. And you take the name of the class, and you add some brackets next to it. Just a quick note on terminology here.

00:17 When I say brackets, I mean round brackets, or parentheses (()). If we come across square, curly, or angled brackets, I’ll explicitly say so.

00:27 But if I just say brackets, I’m referring to round brackets, or parentheses.

00:33 This instantiates the class. You can do this various times, and it will create two instances. The default representation of the class, which is the string between the two chevrons (<>), says that the Point object is at this long number, which just refers to its memory address. And as you can see, these two Point instances have two different addresses indicating that they are two different instances of the Point class.

01:06 Carrying on from before, you have your Cat class. You evaluated just the Cat part of the class, but if you were to take Cat and add the two brackets as if you were calling a function at the end of it, then you get your Cat object with the memory address.

01:25 And if you do that again, you’ll get a new one. And you can do that as many times as you want. That’s the beautiful thing about classes is that you can create many instances of the class, and they’ll all share some attributes, but they’ll all be unique in the sense that they live at separate places, and so you can operate them independently if you want to.

01:49 Empty classes like this do have their uses just as a sort of name for things, but in general, you’ll be wanting to add things to your classes: attributes, methods, all these things are going to come up soon.

02:02 And in the next few lessons, you’re going to learn how to add just those things.

Become a Member to join the conversation.