L = ['Adam', 'Lisa', 'Bart', 'Paul']
for index, name in enumerate(L):
print index+1, '-', name
for index, name in enumerate(L):
print index+1, '-', name
def firstCharUpper(s):
return s[0].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
return s[0].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2016-11-08
sum = 0
x = 1
n = 1
while True:
if n>20:
break
sum=sum+x
n=n+1
x=pow(2,(n-1))
print sum
x = 1
n = 1
while True:
if n>20:
break
sum=sum+x
n=n+1
x=pow(2,(n-1))
print sum
2016-11-08
已采纳回答 / lwen_x
zip(xl,yl)的结果为[(1,9),(3,12),(5,13)],for循环遍历zip(xl,yl)的结果,并赋给(x,y),每一次迭代都进行if判断,当y>10时,把x**2的结果记录到L[]中。所以,y>10的有(3,12)和(5,13),取出其中的x值3和5,求平方后放入L[],就得到[9,25]
2016-11-08
xl = [1,3,5]
yl = [9,12,13]
L = [ x**2 for (x,y) in zip(xl,yl) if y > 10]
这个完全不懂啊
yl = [9,12,13]
L = [ x**2 for (x,y) in zip(xl,yl) if y > 10]
这个完全不懂啊
2016-11-08
最赞回答 / 放肆的白日梦
关于“为什么写成 L=t[2] 而不能写成L=t(2),t是一个tuple不是应该用()吗??”,L=t[2]属于元素索引的表述方式,这和t是tuple,list甚至是数组都没有关系的
2016-11-08