L = ['Adam', 'Lisa', 'Bart']
L[0], L[2] = L[2], L[0]
print L
L[0], L[2] = L[2], L[0]
print L
2019-03-20
L = ['Adam', 'Lisa', 'Bart']
L.reverse()
print L
L.reverse()
print L
2019-03-20
L = [75, 92, 59, 68]
sum = 0.0
for score in L :
sum += score
print sum / 4
sum = 0.0
for score in L :
sum += score
print sum / 4
2019-03-20
s = 'Python was started in 1989 by "Guido".\nPython is free and easy to learn.'
print s
直接中间加个\n即可
print s
直接中间加个\n即可
2019-03-20
利用%输出格式
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key,value in d.items():
print ("%s:%s"%(key,value))
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key,value in d.items():
print ("%s:%s"%(key,value))
2019-03-19
创建列表,再累加
s=[x for x in range(1,1000,3)]
sum=0
for x in s:
sum+=x
if(x==s[99]):
print sum
s=[x for x in range(1,1000,3)]
sum=0
for x in s:
sum+=x
if(x==s[99]):
print sum
2019-03-19
L = ['Adam', 'Lisa', 'Bart']
L[2] = 'Adam'
L[0] = 'Bart'
print L
L[2] = 'Adam'
L[0] = 'Bart'
print L
2019-03-19
x100 =x1
s =x1
while(x100 <n):
x100=x100+d
s=x100+s
s =x1
while(x100 <n):
x100=x100+d
s=x100+s
2019-03-19
L = []
sum=0
for x in range(1,101):
L.append(x*x)
sum=sum+x*x
print sum
sum=0
for x in range(1,101):
L.append(x*x)
sum=sum+x*x
print sum
2019-03-19
[m + n+l for m in '123' for n in '123' for l in '123' if m==l]
2019-03-18
for x in range(1, 10):
for y in range(10):
if x < y:
print x * 10 + y
for y in range(10):
if x < y:
print x * 10 + y
2019-03-18