对不起,是我弄错了,以下两种方法都可以输出
for (key, value) in d.items():
print("%s: %s" % (key, value))
for k in d:
print k
for (key, value) in d.items():
print("%s: %s" % (key, value))
for k in d:
print k
2018-04-12
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for (key, value) in d.items():
print("%s: %s" % (key, value))
上面那种写法,执行的时候会报错,dict没有itmes()
用下面的写法也可以输出
for k in d:
print k
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for (key, value) in d.items():
print("%s: %s" % (key, value))
上面那种写法,执行的时候会报错,dict没有itmes()
用下面的写法也可以输出
for k in d:
print k
2018-04-12
print [a*100+b*10+c for a in range(1,10) for b in range(0,10) for c in range(0,10) if a==c]
2018-04-12
可能这个确实对零基础的同学来说不够友好了,我学过浅薄的HTML css JS JAVA 和c 看这节都有点绕,不过稍微看下就能理解了,如果不理解的同学可以把这节标记下,回头再看。
2018-04-11
for x in range(1,9):
for y in range(x+1,10):
print 10 * x + y
for y in range(x+1,10):
print 10 * x + y
2018-04-11
l=[]
for a in '123456789':
for b in '123456789':
c=a
l.append(a+b+c)
print(l)
for a in '123456789':
for b in '123456789':
c=a
l.append(a+b+c)
print(l)
2018-04-11
import math
def quadratic_equation(a, b, c):
x = b * b - 4 * a * c
if x<0:
return none
else:
x1=(-b+math.sqrt(x))/(2*a)
x2=(-b-math.sqrt(x))/(2*a)
return x1,x2
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
def quadratic_equation(a, b, c):
x = b * b - 4 * a * c
if x<0:
return none
else:
x1=(-b+math.sqrt(x))/(2*a)
x2=(-b-math.sqrt(x))/(2*a)
return x1,x2
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2018-04-11