27、计算题
1、求结果
v=dict.fromkeys(['k1','k2'],[])
v['k1'].append(666)
print(v)
v['k1'] = 777
print(v)
v=dict.fromkeys(['k1','k2'],[]) v['k1'].append(666) print(v) #{'k2': [666], 'k1': [666]} v['k1'] = 777 print(v) #{'k2': [666], 'k1': 777}
2、求结果
def num():
return [lambda x:i*x for i in range(4)]
print(m(2) for m in num())
def num(): return [lambda x:i*x for i in range(4)] print(m(2) for m in num())# <generator object <genexpr> at 0x0000000000B2FA40> 为元祖 print(list(m(2) for m in num())) # [6, 6, 6, 6]
3、求结果
a、[i%2 for i in range(10)]
b、( i % 2 for i in range(10) )
a=[i%2 for i in range(10) ] print(a) # 因为 [] 为列表 所以会有结果为[0, 1, 0, 1, 0, 1, 0, 1, 0, 1] b=(i%2 for i in range(10)) print(b) # 因为()为元祖 所以会有结果为 <generator object <genexpr> at 0x0000000000645D00> c=list(b) # 将元祖转换格式为列表 print(c) # 打印c,结果为 [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]
4、求结果:
a. 1 or 2
b. 1 and 2
c. 1 < (2==2)
d. 1 < 2 == 2
print(1 or 2) # 1 print(1 and 2) # 2 print(1<(2==2)) # False 因为2==2为True,而True表示为1,False表示为0,所以1<1,结果为False print(1<2==2) # True 但是值为什么是True?大神看到请解释一下,谢谢!