-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtestid.py
More file actions
43 lines (35 loc) · 834 Bytes
/
testid.py
File metadata and controls
43 lines (35 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def main():
print "="*20, "数字", "="*20
x = 10
y = 10
print "id(x):", id(x)
print "id(y):", id(y)
print x is y
print "="*20, "字符串", "="*20
x = 10
x ="abcd"
y ="abcd"
print "id(x):", id(x)
print "id(y):", id(y)
print x is y
print "="*20, "数组字典等数据结构", "="*20
d1 = {1: 1, 2: 4}
d2 = {1: 1, 2: 4}
print "id(d1):", id(d1)
print "id(d2):", id(d2)
print d2 == d1 # True
print d2 is d1 # False
d2 = d1
print "id(d1):", id(d1)
print "id(d2):", id(d2)
print d2 == d1 # True
print d2 is d1 # False
del d1[1]
print d2
d1 = {}
print "id(d1):", id(d1) # changed
print "id(d2):", id(d2) # not changed
if __name__ == '__main__':
main()