d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
print sum(d.values())*1.0/len(d.values())
print sum(d.values())*1.0/len(d.values())
2016-05-17
1. 在计算 a and b 时,如果 a 是 False,则根据与运算法则,整个结果必定为 False,因此返回 a;如果 a 是 True,则整个计算结果必定取决与 b,因此返回 b。
2. 在计算 a or b 时,如果 a 是 True,则根据或运算法则,整个计算结果必定为 True,因此返回 a;如果 a 是 False,则整个计算结果必定取决于 b,因此返回 b。
所以Python解释器在做布尔运算时,只要能提前确定计算结果,它就不会往后算了,直接返回结果。
2. 在计算 a or b 时,如果 a 是 True,则根据或运算法则,整个计算结果必定为 True,因此返回 a;如果 a 是 False,则整个计算结果必定取决于 b,因此返回 b。
所以Python解释器在做布尔运算时,只要能提前确定计算结果,它就不会往后算了,直接返回结果。
2016-05-17
print r'''"To be, or not to be": that is the question.
Whether it's nobler in the mind to suffer.'''
Whether it's nobler in the mind to suffer.'''
2016-05-17
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59,
'paul':75
}
还顺序试了试就通不过但是
print d
打印出来是没有问题的
排序依然是无序的
'Adam': 95,
'Lisa': 85,
'Bart': 59,
'paul':75
}
还顺序试了试就通不过但是
print d
打印出来是没有问题的
排序依然是无序的
2016-05-17
>>> print r'''’\"To be,or not to be\":that is the question.\nWheth er it\'s nobler in the mind to suffer.‘'''
’\"To be,or not to be\":that is the question.\nWheth er it\'s nobler in the mind to suffer.‘
’\"To be,or not to be\":that is the question.\nWheth er it\'s nobler in the mind to suffer.‘
2016-05-17
print r''''\"To be,or not to be\":that is the question.\nWheth
er it\'s nobler in the mind to suffer.''''
请检查代码中是否包含:print r'''"to be, or not to be": that is the question.,再试试!
er it\'s nobler in the mind to suffer.''''
请检查代码中是否包含:print r'''"to be, or not to be": that is the question.,再试试!
2016-05-17
已采纳回答 / 不思其反
s = set([('Adam', 95), ('Lisa', 85), ('Bart', 59)])for x in s: print 'x[0]+:',x[1]''中间是字符? 会直接显示出 x[0]+:就好像你 print 'x' 会打印出x 一样 而不是x的值
2016-05-17
然而不加r,print结果是这样的:
>>> print ('''..'..''')
..'..
加r,print 结果是这样的:
>>> print (r'''..'..''')
..'..
结果都是一样的
>>> print ('''..'..''')
..'..
加r,print 结果是这样的:
>>> print (r'''..'..''')
..'..
结果都是一样的
2016-05-17