Skip to content

Instantly share code, notes, and snippets.

@sirpengi
Created January 31, 2012 09:50
Show Gist options
  • Save sirpengi/1709676 to your computer and use it in GitHub Desktop.
Save sirpengi/1709676 to your computer and use it in GitHub Desktop.
>>> a = lambda x: 1000
>>> a
<function <lambda> at 0xb77f88b4>
>>> a(1)
1000
>>> (id(a(1)), id(a(1)))
(143414124, 143414124)
>>> (id(a(1)), id(a(2)))
(143414124, 143414124)
>>> def return_1000(): return 1000
...
>>> (id(return_1000()), id(return_1000()))
(143414160, 143414160)
>>> id(1000)
143414124
>>> id(9999)
143414124
>>> (id(1000), id(9999))
(143414124, 143414208)
>>> id(1000); id(9999)
143414124
143414208
>>> id(1000); id(1000)
143414124
143414124
[sirpengi@newfie ~]$ cat test.py
print id(1000) # 156533708
print id(9999) # 156533684
print id(1000), id(9999) # 156533708 156533684
print id(1000); print id(9999) # 156533708\n 156533684
a = 1000
b = 1000
print id(a) # 156533708
print id(b) # 156533708
print a is b # True
c = 999
print id(c) # 156533600
c += 1
print id(c) # 156533540
print c == a # True
print c is a # False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment