print [int(str(x)+str(y)+str(x)) for x in range(1,10) for y in range(0,10)]
2016-09-24
tds = ['<tr><td>%s</td>%s%s</td></tr>'%(name,('<td>' if score >= 60 else '<td style="color:red">'),score) for name, score in d.iteritems()]
2016-09-24
已采纳回答 / yinyanting
嗯,对于问题1,我觉得应该是L[2]指向的是列表,当列表的指向发生改变的时候,与tuple无关,所以列表中的元素可以改变。但r[2]指向的数字2.当变量a改变时,是又指向了数字3,相当于新生成了一个变量,与原来的变量已经无关了。可参考http://blog.csdn.net/longshenlmj/article/details/13773977对于问题2,这个过程相当于新生成了变量,或者说是一个指向数字3的指针。对于指针的指向来说,可以说是类似的。以上是我的一点理解,欢迎交流。
2016-09-24
已采纳回答 / Seolen
这种问题大可不必纠结,两者本质上是一样的,所谓的更优,也只是习惯而已。具体说来,while true break 结构类似于do while(java中)结构,会保证至少一次进入while循环;而 while +条件 结构更多情况下完全取决于你对是否正确循环的预判,有可能一次都不执行。之前上计算机视觉课程是就发现,涉及多个循环条件判断是,用多个if-break语句其实更明晰。
2016-09-24
sum = 0
x = 1
while x<=100:
if x % 2 != 0:
sum = sum + x
print sum
x = 1
while x<=100:
if x % 2 != 0:
sum = sum + x
print sum
2016-09-24
def greet(flag=''):
print 'Hello,%s.'%flag if flag else 'Hello, world.'
greet()
greet('Bart')
print 'Hello,%s.'%flag if flag else 'Hello, world.'
greet()
greet('Bart')
2016-09-24
def move(n, a, b, c):
if n == 1:
print('%s-->%s'%(a,c)) #一个盘子直接移动
else:
move(n-1,a,c,b)#否则先把n-1个盘子从a,移动到b
move(1,a,b,c) #剩下的一个盘子从a 移动到c
move(n-1,b,a,c)#之后把b上的n-1个盘子借助a移动到c上
move(4, 'a', 'b', 'c')
答案是用的 a,b,c小写,用大写过不了
if n == 1:
print('%s-->%s'%(a,c)) #一个盘子直接移动
else:
move(n-1,a,c,b)#否则先把n-1个盘子从a,移动到b
move(1,a,b,c) #剩下的一个盘子从a 移动到c
move(n-1,b,a,c)#之后把b上的n-1个盘子借助a移动到c上
move(4, 'a', 'b', 'c')
答案是用的 a,b,c小写,用大写过不了
2016-09-23
print r'''"To be, or not to be": that is the question.'\n'Whether it's nobler in the mind to suffer.''''
不是答案有错 也不是别的 这里面会涉及到两次转义 比如:不加r'''...'''的时候 开头的\"、\n就已经是转义的了 如果直接用r'''...'''格式的话 会被再次转义 被当成字符串输出了
不是答案有错 也不是别的 这里面会涉及到两次转义 比如:不加r'''...'''的时候 开头的\"、\n就已经是转义的了 如果直接用r'''...'''格式的话 会被再次转义 被当成字符串输出了
2016-09-23