def greet(n='world'):
print 'Hello,%s.' %(n)
greet()
greet('Bart')
print 'Hello,%s.' %(n)
greet()
greet('Bart')
2019-04-06
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for a in L:
if a in s:
s.remove(a)
else:
s.add(a)
print s
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for a in L:
if a in s:
s.remove(a)
else:
s.add(a)
print s
2019-04-06
sum = 0
x = 1
n = 1
while True:
sum+=x
x*=2
if n == 20 :
break
n+=1
print sum
x = 1
n = 1
while True:
sum+=x
x*=2
if n == 20 :
break
n+=1
print sum
2019-04-06
sum = 0
x = 1
while x>=1 and x<=100:
for num in range(2,101):
if x % num != 0
sum+=x
print sum
x = 1
while x>=1 and x<=100:
for num in range(2,101):
if x % num != 0
sum+=x
print sum
2019-04-06
sys.setdefaultencoding('utf-8') 会导致的两个大问题
简单来说这么做将会使得一些代码行为变得怪异,而这怪异还不好修复,以一个不可见的 bug 存在着
简单来说这么做将会使得一些代码行为变得怪异,而这怪异还不好修复,以一个不可见的 bug 存在着
2019-04-04
sum = 0
x = 1
while x < 100:
if x % 2 == 0:
sum += x
x+=1
print sum
x = 1
while x < 100:
if x % 2 == 0:
sum += x
x+=1
print sum
2019-04-04
L = ['Adam', 'Lisa', 'Paul', 'Bart']
L.pop()
L.pop()
print L
L = ['Adam', 'Lisa', 'Paul', 'Bart']
L.pop(-1)
L.pop(-1)
print L
L.pop()
L.pop()
print L
L = ['Adam', 'Lisa', 'Paul', 'Bart']
L.pop(-1)
L.pop(-1)
print L
2019-04-03
for x in range(1,10):
for y in range(0,10):
if x<y:
print str(x)+str(y)
for y in range(0,10):
if x<y:
print str(x)+str(y)
2019-04-03