Python会把0,空字符串和None看成false,把其他数值和非空字符串看成true。因此a被看成了true,‘world’被看成了true,b被看成了false,而根据“短路计算”,第二行中,运行到a时结果便以确定,因此不再往后面执行,进而输出了hello, python。第四行中,因为b为false,所以会运行到后面的‘world’,输出了hello, world
2015-08-22
t = ('a', 'b', ('a','b'))
print t
经测试,这是对的
print t
经测试,这是对的
2015-08-22
L = [95.5, 85, 59]
print L[-1]
print L[-2]
print L[-3]
#print L[-4]
print L[-1]
print L[-2]
print L[-3]
#print L[-4]
2015-08-22
sum=0
L=[0,1,2,3,4,5,6,7,8,9]
for i in L:
for j in L:
x=10*i+j
a=x*x
x=x+1
sum=sum+a
print sum+10000
L=[0,1,2,3,4,5,6,7,8,9]
for i in L:
for j in L:
x=10*i+j
a=x*x
x=x+1
sum=sum+a
print sum+10000
2015-08-21
print [(m*100)+(n*10)+k for m in range(1,10) for n in range(0,10) for k in range(0,10) if m==k]
2015-08-21
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for index,number in enumerate(d.values()):
sum+=number
print sum/(index+1)
sum = 0.0
for index,number in enumerate(d.values()):
sum+=number
print sum/(index+1)
2015-08-20
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for index,number in enumerate(d.values()):
sum+=number
print sum/index
sum = 0.0
for index,number in enumerate(d.values()):
sum+=number
print sum/index
2015-08-20