Discuss / Python / 奇怪的问题增加了

奇怪的问题增加了

Topic source

v贝塔v

#1 Created at ... [Delete] [Delete and Lock User]

大家去试试这个,有意思

def func(b,a = []):
	if b:
		a = b
	return a

b = [3]
print(func(b),func(None))
# 结果:([3], [])

def func2(b,a = []):
	if b:
		a.append(b)
	return a

b = 3
print(func2(b),func2(None))
# 结果:([3], [3])

  • 1

Reply