Locked learning resources

You must own this product to watch this lesson.

Locked learning resources

You must own this product to watch this lesson.

An Object's Identity, Type, and Value

A quick introduction to today’s topic from me.

00:00 So you may have seen today’s topics and especially in the first one, for example, is on variables. And you may think that’s quite easy. I know that already, and there aren’t many of these topics.

00:10 We very soon move on to more intermediate advanced topics. But this course is about looking at core Python and digging a bit underneath the surface. We want to understand how Python works behind the scenes.

00:24 So for example, today’s topic focuses on one of the key principles in Python. And this is a phrase you may have heard. Everything in Python is an object. And if you haven’t heard this before, you will hear it many times as you go through Python.

00:38 I often like to say almost everything is an object because there are a few things that aren’t, but we’ll discuss those in the forum and the so. So what this means is that the basic building block in Python is this thing called an object.

00:52 This is a bit different from some other languages. Not all programming languages behave in the same way. And this basic unit, the object in Python. So integers, strings, lists, any other data type, but even functions and classes themselves.

01:08 So when we say everything is an object, it’s not just the, the the, the values. We often store integers and strings, functions and classes and, and pretty much everything in Python is built on this unit.

01:23 And there are three main characteristics of an object. It has a value. First of all, that’s the most obvious thing. If it’s the integer 27, the value is 27.

01:35 If it’s a string, its value is the characters you have in the string. If it’s a list, it’s a bit more complex there, but it’s the items in the list. And if it’s yet a more complex data type, for example, a class which has lots of attributes, then the value of the object is all of those attributes, all of the data stored in those attributes.

01:57 So an object has a value, it has a type. It’s really important to know what type of data an object is. Why? Because the type of an object tells us what the object can do and what we can do with that particular object.

02:14 You are familiar with data types, but it’s a topic we’ll dive into a lot more throughout the scores and we’ll figure out what it is that makes a certain type have certain characteristics.

02:26 So an object has to have a value, a type, and it has an identity. So every object is stored somewhere in memory and therefore it has its own unique identification number if you like.

02:38 In fact, in CPython, which is the most common version of Python, you’re almost certainly using the identity

02:46 is the memory address where this object is stored in memory. It’s normally a number. It doesn’t really matter what the number is, but it tells you if you have two objects, they may have the same value, but they may be two separate objects.

03:00 It’s a bit like having two identical cars. They might be identical in everything, color, model, make, whatever, but they’re still two separate cars. So that’s what we mean by the identity.

03:10 So as we go through today’s lessons, always think about the object as this basic unit in Python that has a value, a type, and an identity.

You must own this product to join the conversation.