python 万物皆对象,数字也不例外
def fun(p):
p = p # nothing be changed
print("before:",id(p))
p += 1 # "2" be created
print("after :",id(p))
print(p)
a = 1 # "1" be created
b = 1 # no more "1" be created
fun(a)
print(id(a))
print(id(b))
b += 1
print(id(b))
b -= 1
print(id(b))
OUTPUT
before: 139971409287872
after : 139971409287904
2
139971409287872
139971409287872
139971409287904
139971409287872
139971409287872 139971409287904