这教程挺好的,不过就是python2的
这个已经过时了,好多地方和python3都有出入
比如
int(12.34)在python会报错
python3 中没有imap,ifilter等
python3中字典中没有iteritems,itervalues属性
range,map返回值都是本身对象的地址,不是list列表,和python2也不一样了
这个已经过时了,好多地方和python3都有出入
比如
int(12.34)在python会报错
python3 中没有imap,ifilter等
python3中字典中没有iteritems,itervalues属性
range,map返回值都是本身对象的地址,不是list列表,和python2也不一样了
def square_of_sum(L):
s=0
for x in L:
s += x**2
return s
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
s=0
for x in L:
s += x**2
return s
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2018-10-03
for x in ['1','2','3','4','5','6','7','8','9']:
for y in ['1','2','3','4','5','6','7','8','9']:
if x < y:
print x+y
for y in ['1','2','3','4','5','6','7','8','9']:
if x < y:
print x+y
2018-10-03
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
2018-10-03
sum = 0
x = 1
n = 1
while True:
sum += x
x = 2**n
n += 1
if n > 20:
break
print sum
x = 1
n = 1
while True:
sum += x
x = 2**n
n += 1
if n > 20:
break
print sum
2018-10-03
sum = 0
x = 1
n = 1
while True:
sum += x
x = 2**n
n += 1
if n > 20:
break
print sum
x = 1
n = 1
while True:
sum += x
x = 2**n
n += 1
if n > 20:
break
print sum
2018-10-03
import math
def answer(a,b,c):
if a!=0:
if b**2-4*a*c>=0:
t=math.sqrt(b**2-4*a*c)
return (-b + t) / (2 * a),( -b - t )/ (2 * a)
else:
return None
else:
return None
def answer(a,b,c):
if a!=0:
if b**2-4*a*c>=0:
t=math.sqrt(b**2-4*a*c)
return (-b + t) / (2 * a),( -b - t )/ (2 * a)
else:
return None
else:
return None
2018-10-03
s = 'Python was started in 1989 by \"Guido\".\nPython is free and easy to learn.'
print s
print s
2018-10-02