这里说不太清楚。0代表索引的开始值,-1代表索引的末尾值。
最后一句可以写print L[-1]或print L[2:]
最后一句可以写print L[-1]或print L[2:]
2016-06-12
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-06-12
print r'''"To be, or not to be" :that is the question.
Whether it's nobler in the mind to suffer.'''(错误)
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.'''(错误)
print r'''"To be, or not to be":that is the question.
Whether it's nobler in the mind to suffer.'''(正确)
多了一个空格。。
2016-06-12
按照教程试了老是出错,查了廖雪峰的博客发现一个新方法,直接注释的地方加上#encoding:utf-8,之后就正常输入中文了
#encoding: utf-8
print '''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。
'''
#encoding: utf-8
print '''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。
'''
2016-06-12
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key,value in d.items():
print (key,':',v
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key,value in d.items():
print (key,':',v
2016-06-12
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
print ((sum(d.values()) + 0.0) / len(d))
print ((sum(d.values()) + 0.0) / len(d))
2016-06-12