sum = 0
x = 1
n = 1
while True:
sum=sum+x
x=x*2
n=n+1
if n==21:
break
print sum
x = 1
n = 1
while True:
sum=sum+x
x=x*2
n=n+1
if n==21:
break
print sum
2019-09-18
ss =['Adam', 'Lisa', 'Bart', 'Paul']
s = set(ss)
print s
s = set(ss)
print s
2019-09-18
or:
print(0 or 55) , 结果输出55
print(55 or 0), 结果输出55
print(None or 55) , 结果输出55
print(55 or None), 结果输出55
print('' or 55) , 结果输出55
print(55 or ''), 结果输出55
print(22 or 55) , 结果输出22
print(55 or 22), 结果输出55
print(0 or 55) , 结果输出55
print(55 or 0), 结果输出55
print(None or 55) , 结果输出55
print(55 or None), 结果输出55
print('' or 55) , 结果输出55
print(55 or ''), 结果输出55
print(22 or 55) , 结果输出22
print(55 or 22), 结果输出55
2019-09-17
and:
print(0 and 55), 结果输出0, (先运行到0,发现false, 那一定是false,后面不用继续)
print(55 and 0), 结果输出0, (先运行到55,发现true,结果取决于后面,继续运行)
print(None and 55) , 结果输出None
print(55 and None), 结果输出None
print('' and 55) , 结果输出为空
print(55 and ''), 结果输出为空
print(22 and 55), 结果输出55
print(55 and 22), 结果输出22
print(0 and 55), 结果输出0, (先运行到0,发现false, 那一定是false,后面不用继续)
print(55 and 0), 结果输出0, (先运行到55,发现true,结果取决于后面,继续运行)
print(None and 55) , 结果输出None
print(55 and None), 结果输出None
print('' and 55) , 结果输出为空
print(55 and ''), 结果输出为空
print(22 and 55), 结果输出55
print(55 and 22), 结果输出22
2019-09-17
def average(*args):
if len(args) == 0:
return 0.0
return float(sum(args))/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
if len(args) == 0:
return 0.0
return float(sum(args))/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2019-09-17
print r'''"To be, or not to be": that is the question.
Whether it's nobler in the mind to suffer.'''
Whether it's nobler in the mind to suffer.'''
2019-09-17
L = ['Adam', 'Lisa', 'Bart']
L[2],L[0]=L[0],L[2]
print L
L[2],L[0]=L[0],L[2]
print L
2019-09-16
#coding=utf-8
print 45678+0x12fd2,
print 'learn Python in imooc。'
print 100<99
print 0xff==255
加中文字符需要在前面写上#coding=utf-8
print 45678+0x12fd2,
print 'learn Python in imooc。'
print 100<99
print 0xff==255
加中文字符需要在前面写上#coding=utf-8
2019-09-16