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

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds 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 the default subtitles language 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 see our video player troubleshooting guide to resolve the issue.

Identity: Recap

Give Feedback

Here’s a recap of what you’ve covered about object identity:

  • Object value vs object identity: Objects that have the same value can be separate objects.
  • Small integer caching: The ID of two objects that you might expect to be different can be the same.

Check out the talk Turning ‘wat’ into ‘why’ by Katie McLaughlin that covers an explanation about small integer caching and specifically addresses the Pub Quiz challenge mentioned in this course.

Greish on Dec. 3, 2020

Thank you! Came for learning more about variables, did not get disappointed.

Anthony De La Rosa on Jan. 5, 2021

I’m a beginner and I’m currently doing the Learning Path: Intro to Python so the quiz is just not fair. We haven’t learned about ranges, for loops or even if statements so although I like a challenge, it would be nice if this was explained before given a quiz like that.

Martin Breuss RP Team on Jan. 6, 2021

Hi @Anthony, are you following the Learning Path Introduction to Python?

Did you maybe mix up the quizzes somehow? I just clicked through the Python Variables Quiz that follows this course, and it doesn’t include any questions about ranges, loops, or conditionals.

Where did you find the link to the quiz? Let us know so we can double-check that there’s no rogue link anywhere that points to a more advanced quiz too early! Thanks! :)

Anthony De La Rosa on Jan. 6, 2021

Hey Martin :)

I am following this link: I am basically following that list of courses one after the other. Sorry about the comment but I was thrown off by it. I plan to complete the whole list and move on to the next part.

Martin Breuss RP Team on Jan. 7, 2021

Hi again @Anthony, nice job that you’re going through the whole list! There’s a lot to learn but if you stick with it and keep going, things will start to come together :)

You should see the Learning Path like in this screenshot, which puts the Python Variables Quiz right after this course on Variables in Python.

Click that link and you’ll be in the right quiz that tests the topics covered in this course. Hope that helps and keep learning :)

Ashutosh Kumar on April 1, 2021

I tried print(id(a)) and print(id(b)) in sublime text editor using values as high as 3000. I am getting the same id for both “a” and “b”. Can someone please help me clarify?

Bartosz Zaczyński RP Team on April 2, 2021

@Ashutosh Kumar That’s interesting. Can you paste the exact piece of code that you’re running, please?

g2sgautam on April 17, 2021

@Ashutosh Kumar

I am using Python 3.7 and interning varies from version to version

Depends on how you execute the line and what python interpreter sees at the moment

In a python file

x = 1000056475364665758
y = 1000056475364665758
print(f"x address {id(x)}, y address {id(y)}")

OUTPUT x address 2111466067968, y address 2111466067968

In a REPL interpreter

>>> x = 1000056475364665758
>>> y = 1000056475364665758
>>> id(x), id(y)
(2319921208016, 2319921208056)

Also now if you change the way you execute

>>> x = 1000056475364665758; y = 1000056475364665758; id(x), id(y)
(2319922547288, 2319922547288)

When both the x and y values are visible to interpreter at once it can perform many optimizations on top of existing small integers cache.

For integers in range of -5 to 256 no matter how you execute it is always fetched from cache

>>> id(x), id(y)
(140706469252640, 140706469252640)
>>> x = 10; y=10; id(x), id(y)
(140706469244960, 140706469244960)

Martin Breuss RP Team on April 18, 2021

Great answer, thanks @g2sgautam! 🙌

lemaychris on May 5, 2021

Hello, I don’t see the links that discuss the pub quiz. Are they in this lecture or located somewhere else?



Martin Breuss RP Team on May 6, 2021

Hi @lemaychris, thanks for the heads-up! I’ve added the link in the Description tab of this video. Here it is again:

Turning ‘wat’ into ‘why’ by Katie McLaughlin

Become a Member to join the conversation.