L = ['Adam', 'Lisa', 'Bart']
L[0]='Bart'
L[2]='Adam'
print L
L[0]='Bart'
L[2]='Adam'
print L
2015-05-25
L = ['Adam', 'Lisa', 'Paul', 'Bart']
L.pop(2)
print L
L.pop(2)
print L
L.pop(2)
print L
L.pop(2)
print L
2015-05-25
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
2015-05-25
sum = 0
x = 0
while True:
x = x + 1
if x > 100:
break
if x%2 == 0:
continue
sum += x
print sum
x = 0
while True:
x = x + 1
if x > 100:
break
if x%2 == 0:
continue
sum += x
print sum
2015-05-25
sum = 0
x = 1
n = 1
while True:
sum += x
x *= 2
n += 1
if n>20:
break
print sum
x = 1
n = 1
while True:
sum += x
x *= 2
n += 1
if n>20:
break
print sum
2015-05-25
def move(n, a, b, c):
while n>0:
if n==1:
print a+'-->'+c
else:
print a+'-->'+b
return move(n-1,a,b,c)
move(4, 'A', 'B', 'C')
while n>0:
if n==1:
print a+'-->'+c
else:
print a+'-->'+b
return move(n-1,a,b,c)
move(4, 'A', 'B', 'C')
2015-05-25
sum = 0
x = 1
while x < 100:
sum += x
x += 2
print sum
x = 1
while x < 100:
sum += x
x += 2
print sum
2015-05-25
import math
def quadratic_equation(a, b, c):
if b**2-4*a*c<0:
print 'none'
else:
x1=(-b+math.sqrt(b**2-4*a*c))/2*a
x2=(-b-math.sqrt(b**2-4*a*c))/2*a
return x1,x2
print quadratic_equation(2,1, 0)
print quadratic_equation(3, -6, 5)
def quadratic_equation(a, b, c):
if b**2-4*a*c<0:
print 'none'
else:
x1=(-b+math.sqrt(b**2-4*a*c))/2*a
x2=(-b-math.sqrt(b**2-4*a*c))/2*a
return x1,x2
print quadratic_equation(2,1, 0)
print quadratic_equation(3, -6, 5)
2015-05-24
tuple所谓的“不变”是说,tuple的每个元素,指向永远不变。即指向'a',就不能改成指向'b',指向一个list,就不能改成指向其他对象,但指向的这个list本身是可变的!
2015-05-24