标签:print nbsp bsp 命令 app 代码 append range []
l = []
for i in xrange(10):
l.append({‘num’:i})
print l
在考虑以下代码,运行结束后的结果是什么?
l = []
a = {‘num’:0}
for i in xrange(10):
a[‘num’] = i
l.append(a)
print l
以上两段代码的运行结果是否相同,如果不相同,原因是什么?
上方代码的结果:
1. [{‘num’:0},{‘num’:1},{‘num’:2},{‘num’:3},{‘num’:4},{‘num’:5},{‘num’:6},{‘num’:7},{‘num’:8},
{‘num’:9}]
下方代码结果:
1. [{‘num’:9},{‘num’:9},{‘num’:9},{‘num’:9},{‘num’:9},{‘num’:9},{‘num’:9},{‘num’:9},{‘num’:9},
{‘num’:9}]
考虑以下 Python 代码,如果运行结束,命令行中的运行结果是什么?
标签:print nbsp bsp 命令 app 代码 append range []
原文地址:https://www.cnblogs.com/hellohorld/p/9744181.html