def square_of_sum(L):
s = [x**2 for x in L]
return sum(s)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
s = [x**2 for x in L]
return sum(s)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2018-05-02
s = set([('Adam', 95), ('Lisa', 85), ('Bart', 59)])
for name in s:
print ("%s:%s" %name)
for name in s:
print ("%s:%s" %name)
2018-05-02
s = set([('Adam', 95), ('Lisa', 85), ('Bart', 59)])
for key in s:
print ("%s:%s" %key)
for key in s:
print ("%s:%s" %key)
2018-05-02
用len()? 不存在的
def average(*args):
n=0.0
m=0.0
for x in args:
n=n+x
m=m+1
if n==0.0:
return 0.0
return n/m
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
def average(*args):
n=0.0
m=0.0
for x in args:
n=n+x
m=m+1
if n==0.0:
return 0.0
return n/m
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2018-05-02
L = ['Adam', 'Lisa', 'Paul', 'Bart']
L.pop(2)
L.pop(2)
print L
这样也可以的哇~~
L.pop(2)
L.pop(2)
print L
这样也可以的哇~~
2018-05-02
print('hello'+','+'python')
print("hello"+","+"python")
print("hello"+","+"python")
2018-05-02
#这个窗口的解释应该是python 2的版本
# -*- coding: utf-8 -*-
print '''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。'''
# -*- coding: utf-8 -*-
print '''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。'''
2018-05-02
python 3.6 运行
# -*- coding: utf-8 -*-
print (u'''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。''')
# -*- coding: utf-8 -*-
print (u'''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。''')
2018-05-02
L = [75, 92, 59, 68]
sum = 0.0 #定义sum为浮点数
for i in L:
sum += i
print sum / 4
sum = 0.0 #定义sum为浮点数
for i in L:
sum += i
print sum / 4
2018-05-02
sum = 0
x = 0
while True:
x = x + 1
if x > 100:
break
elif x%2==0:
continue
sum+=x
print sum
x = 0
while True:
x = x + 1
if x > 100:
break
elif x%2==0:
continue
sum+=x
print sum
2018-05-02
sum = 0
x = 1
while x<=100:
if x%2>0:
sum=sum+x
x=x+1
print sum
x = 1
while x<=100:
if x%2>0:
sum=sum+x
x=x+1
print sum
2018-05-02