最新回答 / qq_雨落
tuple实际上是一种特殊的list,就是说tuple是一种元素指向不可改变的list(list元素指向可改变),所以list可以直接变成tuple,相当于限定了list的元素指向不能改变,但指向是相同的
2016-12-26
为什么输入数字后 结果都是excellent
score = raw_input("Please tall me your score:")
if score >= 90:
print "excellent"
else:
if score >= 80:
print "good"
else:
if score >= 60:
print "passed"
else:
print "failed"
score = raw_input("Please tall me your score:")
if score >= 90:
print "excellent"
else:
if score >= 80:
print "good"
else:
if score >= 60:
print "passed"
else:
print "failed"
2016-12-26
最赞回答 / 付付meow
你把else:if改成elif试试,score = raw_input("Please tall me your score:") if score >= 90: print "excellent" elif score >= 80: print "good" elif score >= 60: print "passed" else: print "failed"
2016-12-26
def generate_tr(name, score):
format1 = '<tr><td>{}</td><td>{}</td></tr>'
format2 = '<tr><td>{}</td><td style="color:red">{}</td></tr>'
if score >= 60 : return format1.format(name, score)
return format2.format(name, score)
format1 = '<tr><td>{}</td><td>{}</td></tr>'
format2 = '<tr><td>{}</td><td style="color:red">{}</td></tr>'
if score >= 60 : return format1.format(name, score)
return format2.format(name, score)
2016-12-26
def toUppers(L):
return [x.upper() for x in L if isinstance(x,str)]
print toUppers(['Hello', 'world', 101])
return [x.upper() for x in L if isinstance(x,str)]
print toUppers(['Hello', 'world', 101])
显然是两层:
print [i1*100+i2*10+i1 for i1 in range(1,10) for i2 in range(10)]
print [i1*100+i2*10+i1 for i1 in range(1,10) for i2 in range(10)]
2016-12-26
不要输入u,-*- coding: utf-8 -*- 这句已经起到中文编码的效果了
# -*- coding: utf-8 -*-
print '''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。'''
# -*- coding: utf-8 -*-
print '''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。'''
2016-12-26
print 45678+0x12fd2
print'Learn Python in imooc'
print 100<99
print 0xff==255
print'Learn Python in imooc'
print 100<99
print 0xff==255
2016-12-26
感觉这节对 raw 字符串讲的不是很清晰
以下例子不知如何解释:
>>> print r'''''"hahaha'''
''"hahaha
>>> print r'''''''"hahaha'''
"hahaha
>>>
以下例子不知如何解释:
>>> print r'''''"hahaha'''
''"hahaha
>>> print r'''''''"hahaha'''
"hahaha
>>>
2016-12-25
re: 但是r'...'表示法不能表示多行字符串,也不能表示包含'和 "的字符串(为什么?)
疑问:r'...'应该可以包含双引号的字符串
测试结果:
>>> s = r'"我被双引号括着呢"'
>>> print s
"我被双引号括着呢"
>>>
Python 2.7.10
疑问:r'...'应该可以包含双引号的字符串
测试结果:
>>> s = r'"我被双引号括着呢"'
>>> print s
"我被双引号括着呢"
>>>
Python 2.7.10
2016-12-25
def average(*args):
sum = 0.0
if len(args)!=0:
for a in args:
sum = a +sum
return sum/len(args)
else:
return sum
print sum
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
sum = 0.0
if len(args)!=0:
for a in args:
sum = a +sum
return sum/len(args)
else:
return sum
print sum
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2016-12-25